-
Notifications
You must be signed in to change notification settings - Fork 890
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
catch potential write errors on fatal flush sync #740
Conversation
Instead of the flag can we use a try/catch of a sync write and then fallback to the non-sync write in the catch |
Thanks for the fast feedback. |
Not any more, but it doesn’t matter because fatal should only be used when
a process has to die, so it’s never in a hot path
…On Mon, 11 Nov 2019 at 11:03, Tommaso Allevi ***@***.***> wrote:
Thanks for the fast feedback.
Does try/catch drop the performance down?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#740?email_source=notifications&email_token=AAJCWPA5DRMH4ZXCKT2W45DQTE3ZFA5CNFSM4JLT2ZEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDWOWTI#issuecomment-552397645>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJCWPAYQTQK7SV37F3LBFDQTE3ZFANCNFSM4JLT2ZEA>
.
|
I’m with @mcollina right now, we’re discussing it. If the sync write fails the async write will fail too (but silently). So if we want silent failure of the write it should be wrapped in the try catch but with an empty catch. Or rethrow with a more descriptive error |
|
What's your use case of flushing data on logger.fatal('something went really wrong, crashing')
process.exit(1) In this case, if we remove the Is a bad crash better or worse than a swallowed log message? |
It's clear the reason for NB:
this lines work differently allowing the fatal log to crash the app without a fd cleaning up. I've implemented the try catch without the retry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Can you update the title of this PR? |
Done |
I'm not entirely sure we should swallow the error though, wouldn't we want to let the user know that their final log message wasn't written? Instead shouldn't we rethrow an error explaining that? |
lib/levels.js
Outdated
try { | ||
stream.flushSync() | ||
} catch (e) { | ||
// do nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can't write a log message that the user will maybe see, what do you intend to do to alert them to that message not being written? From the limited understanding I have of the issue, at this point everything is fucked at this point so 🤷♂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right but it's worth knowing about? this just swallows it
if we throw an error there will be an understanding that something is wrong
or we can even just console.warn
if throwing seems too drastic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the try/catch
and it will throw. Wasn't the point of this to remove the throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. but the message thrown has clearly caused confusion, we could throw an error with more of an explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂ @mcollina
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think swallowing the error is ok here. Essentially we can not write a log line that says we are dying by a fatal error. Notifying a developer is usually done via log files.. which we cannot use in this stance. I think this is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compromise: update the useless “do nothing” comment with a link to the discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your patience @allevo - if you're happy to accept the suggestion we should be good to merge
Co-Authored-By: David Mark Clements <david.mark.clements@gmail.com>
You are welcome. Opinion sharing is needed to build better software 😄 |
yes!
Il 15 nov 2019, 20:47 +0100, Tommaso Allevi <notifications@github.com>, ha scritto:
… @allevo commented on this pull request.
In test/levels.test.js:
> @@ -417,3 +417,17 @@ test('fatal method sync-flushes the destination if sync flushing is available',
instance.fatal('this is fatal')
})
})
+
+test('fatal method should call async when sync-flushing fails', ({ equal, fail, doesNotThrow, plan }) => {
+ plan(2)
+ const messages = [
+ 'this is fatal 1'
+ ]
+ const stream = sink((result) => equal(result.msg, messages.shift()))
+ stream.flushSync = () => { throw new Error('Error') }
+ stream.flush = () => fail('flush should be called')
+
+ const instance = pino(stream)
+ doesNotThrow(() => instance.fatal(messages[0]))
+ once(stream, 'data')
Test what?
The return value?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
fix #739
This PR allows the developer to choose if flush sync on fatal.
The default is
false
Bench:
this branch
master