Skip to content

Pino-socket blocks other transports when TCP server is not available at start #107

@brjakab

Description

@brjakab

Given this snippet:

const transport = pino.transport({
  targets: [
    {
      target: 'pino-pretty',
      level: 'debug',
    },
    {
      target: 'pino-socket',
      level: 'debug',
      options: {
        address: 'localhost',
        port: '10000',
        mode: 'tcp',
        reconnect: false,
      },
    },
  ],
});

const logger = pino(
  {
    level: 'debug',
    name: 'pino-socket-test',
    timestamp: pino.stdTimeFunctions.isoTime,
  },
  transport,
);

logger.info('first log');

setInterval(() => {
  logger.info('interval log');
}, 5 * 1000);

If my TCP server is running on localhost port 10000, all is working correctly.

Problem:

  1. But if I stop the server and then run this script, then I get this error in the console:
Error: the worker has exited

And my script exists.

  1. If I set reconnecting to true instead, my script just hangs and never logs anything.

Solution:

If I remove the wait for the connection to open:

await once(connection, 'open')

Then other transports, in this case pino-pretty, can start logging in both cases, and no error occurs.

Can this be removed or at least be configurable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions