pinojs / pino

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

`Error: end() failed` when using multiple instance of pino (default 'pino/file') #1241

Closed aduponchel closed 2 years ago

aduponchel commented 2 years ago

I have created the smallest code possible to reproduce easily. My use case is more complex. What I would like is :

It works but it terminate dirty with the following error. Is there an alternative ? However, if an external lib use pino like I currently do, it may have conflit, right ?

Step to reproduce

const pino = require('pino');
const main = pino(
    {
      transport: {
        target: 'pino/file',
      },
    },
);

const child = pino(
    {
      transport: {
        target: 'pino/file',
      },
    },
);

main.info('Hello world');
main.error(new Error('Main Error'));

child.info('Hello Child');
child.error(new Error('Child Error'));

node demo.js | pino-pretty

[1637948848359] INFO (25146 on ***): Hello world
[1637948848360] ERROR (25146 on ***): Main Error
    err: {
      "type": "Error",
      "message": "Main Error",
      "stack":
          Error: Main Error
              at Object.<anonymous> (/home/***/***/demo.js:54:12)
              at Module._compile (node:internal/modules/cjs/loader:1101:14)
              at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
              at Module.load (node:internal/modules/cjs/loader:981:32)
              at Function.Module._load (node:internal/modules/cjs/loader:822:12)
              at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
              at node:internal/main/run_main_module:17:47
    }
[1637948848360] INFO (25146 on ***): Hello Child
[1637948848360] ERROR (25146 on ***): Child Error
    err: {
      "type": "Error",
      "message": "Child Error",
      "stack":
          Error: Child Error
              at Object.<anonymous> (/home/***/***/demo.js:57:13)
              at Module._compile (node:internal/modules/cjs/loader:1101:14)
              at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
              at Module.load (node:internal/modules/cjs/loader:981:32)
              at Function.Module._load (node:internal/modules/cjs/loader:822:12)
              at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
              at node:internal/main/run_main_module:17:47
    }
node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: end() failed
    at end (/home/***/***/node_modules/thread-stream/index.js:394:15)
    at ThreadStream.end (/home/***/***/node_modules/thread-stream/index.js:253:5)
    at autoEnd (/home/***/***/node_modules/pino/lib/transport.js:74:10)
    at process.wrap (/home/***/***/node_modules/on-exit-leak-free/index.js:10:7)
    at Object.onceWrapper (node:events:510:26)
    at process.emit (node:events:402:35)
Emitted 'error' event on ThreadStream instance at:
    at destroy (/home/***/***/node_modules/thread-stream/index.js:341:12)
    at end (/home/***/***/node_modules/thread-stream/index.js:407:5)
    at ThreadStream.end (/home/***/***/node_modules/thread-stream/index.js:253:5)
    [... lines matching original stack trace ...]
    at process.emit (node:events:402:35)
mcollina commented 2 years ago

This looks like a bug on our end as should terminate cleanly.

However I think you should refactor your code to only have one main logger or have two logger writing to different destinations.

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.