Skip to content

Commit

Permalink
Default fd=1 in pino.destination if stdout has no file descriptor (#1517
Browse files Browse the repository at this point in the history
)

Signed-off-by: Matteo Collina <hello@matteocollina.com>

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Aug 12, 2022
1 parent b599eee commit 4d72bcd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tools.js
Expand Up @@ -350,6 +350,11 @@ function normalizeDestFileDescriptor (destination) {
if (typeof destination === 'string' && Number.isFinite(fd)) {
return fd
}
// destination could be undefined if we are in a worker
if (destination === undefined) {
// This is stdout in UNIX systems
return 1
}
return destination
}

Expand Down
7 changes: 7 additions & 0 deletions test/stdout-protection.test.js
Expand Up @@ -30,3 +30,10 @@ test('do not crash if process.stdout has no fd', async ({ teardown }) => {
teardown(function () { process.stdout.fd = fd })
pino()
})

test('use fd=1 if process.stdout has no fd in pino.destination() (worker case)', async ({ teardown }) => {
const fd = process.stdout.fd
delete process.stdout.fd
teardown(function () { process.stdout.fd = fd })
pino.destination()
})

0 comments on commit 4d72bcd

Please sign in to comment.