pinojs / pino

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

Pino fails to flush on process exit when lots of data #2054

Closed erezarnon closed 1 week ago

erezarnon commented 3 weeks ago

It doesn't happen every time, but very often if you run the below, This is a test error, won't get logged. Interestingly, it's only reproducible with the pino-pretty target (not sure if I should file it there).

import pino from 'pino';

const logger = pino({
  transport: {
    target: 'pino-pretty',
  },
});

function main() {
  const longString = 'x'.repeat(100000);
  logger.error(longString);
  throw new Error('This is a test error');
}

if (require.main === module) {
  try {
    main();
  } catch (e) {
    logger.error(e.message);
  }
}
jsumners commented 2 weeks ago

Transports are executed in a separate thread. Worker threads get destroyed at https://github.com/pinojs/pino/blob/7cff45a1d6e90697db330121e5b3fb689e8623e3/lib/transport.js#L32-L55

I suspect the thread is destroyed before logger.error is fired.