Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresponsive logging when using tail, jq and pino-pretty #424

Open
samholmes opened this issue May 1, 2023 · 5 comments
Open

Unresponsive logging when using tail, jq and pino-pretty #424

samholmes opened this issue May 1, 2023 · 5 comments

Comments

@samholmes
Copy link

tail -f my.log | jq -Mc 'select(.msg != "some excluded message") | pino-pretty

The above command does not appear to be responsive. I have a heartbeat log every 10 seconds, yet the log isn't printed immediately. Instead a bunch of logs are printed after some many minutes in a batch. If I remove pino-pretty from the command, the logs are printed immediately. It appears as though pino-pretty is buffering logs? I'm using version 10.0.0.

@jsumners
Copy link
Member

jsumners commented May 1, 2023

Line 80 of bin.js is where the destination stream gets built. That ends up being an abstract-transport instance, which if I remember correctly, will default to a buffered sonic-boom instance. It would be worthwhile to verify this is correct. If so, a PR to added a CLI switch to disable buffering would be a good solution.

@samholmes
Copy link
Author

Why would it take so long to empty the buffer though? Even if it were buffered, why is it that the sonic-boom instance hangs for so long?

@jsumners
Copy link
Member

jsumners commented May 2, 2023

The default options that get passed from the CLI script into the stream factory are:

{
  errorLikeObjectKeys: 'err,error',
  errorProps: ''
}

This means the factory will execute:

pino-pretty/index.js

Lines 229 to 234 in a4fa4e1

destination = buildSafeSonicBoom({
dest: opts.destination || 1,
append: opts.append,
mkdir: opts.mkdir,
sync: opts.sync // by default sonic will be async
})

And thus, sonic-boom will be in asynchronous mode. Therefore:

  1. Data will be written to a buffer until the buffer is full via https://github.com/pinojs/sonic-boom/blob/775b10b2916134cdedabe79d20ed50f25944f2ad/index.js#L237
  2. The closing of the pipe will eventually trigger the stream's end method
  3. That in turn hits https://github.com/pinojs/sonic-boom/blob/775b10b2916134cdedabe79d20ed50f25944f2ad/index.js#L410
  4. And finally it's probably hitting https://github.com/pinojs/sonic-boom/blob/775b10b2916134cdedabe79d20ed50f25944f2ad/index.js#L142-L145

So my wild guess is that the OS is issuing EAGAIN or EBUSY. 🤷‍♂️ someone will need to debug the issue to make an actual determination. Or, more simply, add a switch for the CLI to enable synchronous mode.

@esmiralha

This comment has been minimized.

@martijnarts

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants