Skip to content

Fix some cases of concurrent panics and backtraces #241

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

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

@alexcrichton alexcrichton commented Aug 15, 2019

This commit adds an awful hack to this crate to attempt to mitigate the
issue of concurrently generating a backtrace in the standard library via
RUST_BACKTRACE=1 and also generating a backtrace with this crate. On
Windows the system library that we used for doing this is required to be
single-threaded but we don't actually provide such a guarantee when
using this crate because we can't easily synchronize with the standard
library.

The hack applied in this crate is to use a panic hook to inject
ourselves into the panic process and ensure that panics are synchronized
with generating a backtrace. The commit itself has a lot more comments
about how this is not a complete nor a bullet-proof solution. It's just
sort of the best approximation I think we can do with stable Rust.
Long-term we're going to want to have some sort of official stable API
in libstd to do this coordination.

cc #230

@alexcrichton
Copy link
Member Author

@sfackler mind double-checking me on this logic and this patch? This doesn't actually affect the standard library at all, just the crates.io version of this crate. I'm curious to get your take on this strategy and the general problem as well

This commit adds an awful hack to this crate to attempt to mitigate the
issue of concurrently generating a backtrace in the standard library via
`RUST_BACKTRACE=1` and also generating a backtrace with this crate. On
Windows the system library that we used for doing this is required to be
single-threaded but we don't actually provide such a guarantee when
using this crate because we can't easily synchronize with the standard
library.

The hack applied in this crate is to use a *panic hook* to inject
ourselves into the panic process and ensure that panics are synchronized
with generating a backtrace. The commit itself has a lot more comments
about how this is not a complete nor a bullet-proof solution. It's just
sort of the best approximation I think we can do with stable Rust.
Long-term we're going to want to have some sort of official stable API
in libstd to do this coordination.
@sfackler
Copy link
Member

How about using a session-scoped named lock to synchronize between std's backtrace and the normal backtrace? https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createmutexa

@alexcrichton
Copy link
Member Author

Wow that's a way better idea, nice thinking! I'll implement that soon

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.

2 participants