(err, n)
| 372 | [SymbolDispose]() { this.destroy(); } |
| 373 | |
| 374 | #release(err, n) { |
| 375 | if (err) { |
| 376 | if ((err.code === 'EAGAIN' || err.code === 'EBUSY') && |
| 377 | this.#retryEAGAIN(err, this.#writingBuf.length, this.#len - this.#writingBuf.length)) { |
| 378 | if (this.#sync) { |
| 379 | // This error code should not happen in sync mode, because it is |
| 380 | // not using the underlining operating system asynchronous functions. |
| 381 | // However it happens, and so we handle it. |
| 382 | // Ref: https://github.com/pinojs/pino/issues/783 |
| 383 | try { |
| 384 | sleep(BUSY_WRITE_TIMEOUT); |
| 385 | this.#release(undefined, 0); |
| 386 | } catch (err) { |
| 387 | this.#release(err); |
| 388 | } |
| 389 | } else { |
| 390 | // Let's give the destination some time to process the chunk. |
| 391 | setTimeout(() => this.#fsWrite(), BUSY_WRITE_TIMEOUT); |
| 392 | } |
| 393 | } else { |
| 394 | this.#writing = false; |
| 395 | |
| 396 | this.emit('error', err); |
| 397 | } |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | this.emit('write', n); |
| 402 | const releasedBufObj = releaseWritingBuf(this.#writingBuf, this.#len, n); |
| 403 | this.#len = releasedBufObj.len; |
| 404 | this.#writingBuf = releasedBufObj.writingBuf; |
| 405 | |
| 406 | if (this.#writingBuf.length) { |
| 407 | if (!this.#sync) { |
| 408 | this.#fsWrite(); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | try { |
| 413 | do { |
| 414 | const n = this.#fsWriteSync(); |
| 415 | const releasedBufObj = releaseWritingBuf(this.#writingBuf, this.#len, n); |
| 416 | this.#len = releasedBufObj.len; |
| 417 | this.#writingBuf = releasedBufObj.writingBuf; |
| 418 | } while (this.#writingBuf.length); |
| 419 | } catch (err) { |
| 420 | this.#release(err); |
| 421 | return; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | if (this.#fsync) { |
| 426 | this.#fs.fsyncSync(this.#fd); |
| 427 | } |
| 428 | |
| 429 | const len = this.#len; |
| 430 | if (this.#reopening) { |
| 431 | this.#writing = false; |
no test coverage detected