Skip to content

Fix potential double panic when logging inside panic hook#226

Open
TheJokr wants to merge 2 commits into
mainfrom
lblocher/hook-double-panic
Open

Fix potential double panic when logging inside panic hook#226
TheJokr wants to merge 2 commits into
mainfrom
lblocher/hook-double-panic

Conversation

@TheJokr

@TheJokr TheJokr commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

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.

Closes #224

- Ensure context fields are included in the panic log.
- Verify that an error in the `slog::Drain` does not cause the process
  to abort.
@TheJokr TheJokr self-assigned this Jun 29, 2026
@TheJokr TheJokr requested a review from fisherdarling June 29, 2026 18:59
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.
@TheJokr TheJokr force-pushed the lblocher/hook-double-panic branch from 9e56c3f to 5d123dc Compare June 30, 2026 08:46
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

Successfully merging this pull request may close these issues.

Potential double-panic in foundation's panic hook

1 participant