Fix potential double panic when logging inside panic hook#226
Open
TheJokr wants to merge 2 commits into
Open
Conversation
- Ensure context fields are included in the panic log. - Verify that an error in the `slog::Drain` does not cause the process to abort.
Inside a panic hook, any new panic is automatically a double panic and aborts the process. We very much would like to avoid this, but our logger can panic when it fails to do output. This means we need to work around panics from our logger. To do so, we lift the `Fuse` wrapper that converts `slog::Drain` errors into panics from our root drain into the `build_log_with_drain` helper (where we also add log level filtering.) We can then access the unfused root drain directly when logging panics and ignore errors returned from it. A new internal `log_to_drain` helper function makes this available to the entire foundations crate.
9e56c3f to
5d123dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inside a panic hook, any new panic is automatically a double panic and
aborts the process. We very much would like to avoid this, but our
logger can panic when it fails to do output. This means we need to work
around panics from our logger.
To do so, we lift the
Fusewrapper that convertsslog::Drainerrorsinto panics from our root drain into the
build_log_with_drainhelper(where we also add log level filtering.) We can then access the unfused
root drain directly when logging panics and ignore errors returned from
it. A new internal
log_to_drainhelper function makes this availableto the entire foundations crate.
Closes #224