-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document that the error event on the thread stream is fatal (#2116)
* Document that the error event on the thread stream is fatal Signed-off-by: Matteo Collina <[email protected]> * Update api.md Co-authored-by: Igor Savin <[email protected]> * Update docs/api.md Co-authored-by: James Sumners <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]> Co-authored-by: Igor Savin <[email protected]> Co-authored-by: James Sumners <[email protected]>
- Loading branch information
1 parent
ad864b7
commit 8ab2971
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { Writable } = require('node:stream') | ||
|
||
module.exports = () => | ||
new Writable({ | ||
autoDestroy: true, | ||
write (chunk, enc, cb) { | ||
setImmediate(() => { | ||
/* eslint-disable no-empty */ | ||
for (let i = 0; i < 1e3; i++) {} | ||
process.exit(0) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
const { join } = require('node:path') | ||
const { once } = require('node:events') | ||
const { setImmediate: immediate } = require('node:timers/promises') | ||
const { test } = require('tap') | ||
const pino = require('../../') | ||
|
||
test('pino.transport emits error if the worker exits with 0 unexpectably', async ({ same, teardown, equal }) => { | ||
// This test will take 10s, because flushSync waits for 10s | ||
const transport = pino.transport({ | ||
target: join(__dirname, '..', 'fixtures', 'crashing-transport.js'), | ||
sync: true | ||
}) | ||
teardown(transport.end.bind(transport)) | ||
|
||
await once(transport, 'ready') | ||
|
||
let maybeError | ||
transport.on('error', (err) => { | ||
maybeError = err | ||
}) | ||
|
||
const logger = pino(transport) | ||
for (let i = 0; i < 100000; i++) { | ||
logger.info('hello') | ||
} | ||
|
||
await once(transport.worker, 'exit') | ||
|
||
await immediate() | ||
|
||
same(maybeError.message, 'the worker has exited') | ||
}) |