pino: pino issues `process.exit` when it isn't the controlling process

When pino is in “extreme” mode it has to register handlers for process.on('exit') (https://github.com/mcollina/pino/blob/master/pino.js#L390). These handlers are necessary so that pino can flush the extreme mode cache prior to the process exiting, or else there is the potential for data loss. After flushing the cache, pino then checks to see if its events are in the event queue (https://github.com/mcollina/pino/blob/master/pino.js#L98). If so, pino issues a process.exit().

It is my opinion that a logger should not be invoking process.exit. That should be left up to the application that included pino. However, once event handlers are registered on process the process doesn’t respond to signals like SIGTERM normally; at this point it is up to the application to deal with those signals.

I think there are a couple possible solutions:

  1. instead of issuing process.exit pino can issue its own “exit” event so that the actual application can do what it needs to do for shutdown
  2. pino can accept a callback during initialization that will be invoked after the cache flushing

In either case, this moves the responsibility of terminating the process to the actual application. And it removes the surprise process.exit within pino.

Thoughts, @mcollina @davidmarkclements ?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Bumping as reminder for this to be discussion point in austin @jsumners @mcollina