pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

piping pino break servers that catch sigint when using ctrl-c #357

Closed yonjah closed 6 years ago

yonjah commented 6 years ago

If you pipe pino to get a nicely formatted output for your logs using ctrl-c can cause the server to throw an exception. This is because the shell will send SIGINT to both pino and your server code. pino will immediately exit but if your server is trying to do some graceful termination and logging in he process it will crash since pino already closed stdout.

Example server code -

'use strict'

const pino = require('pino')()

pino.info('starting server')
const interval = setInterval(function () {
    pino.info('server running')
}, 1000);

process.on('SIGINT', () => {
    pino.info('server stopping server')
    setTimeout(() => {
        clearInterval(interval)
        pino.info('server stopped')
    }, 1000)
})

if you run node server.js | pino and terminate the process using ctrl-c the following error is thrown -

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at _errnoException (util.js:1024:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:867:14)
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.