-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
std implementation of panic might not detect double panicking #27598
Comments
There’s two underlying reasons:
|
There will inevitably be some set of code which runs between the decision to panic and then the check to see if we're already panicking, so is there something actionable we can do here? Was a bug uncovered or are there specific mitigation tactics you have in mind? |
My primary concern is use of As far as TLS goes, the only case it can panic is when the value impls Drop. Since Cells of bools are primitive values, using a simple non-std implementation of thread locals should get rid of any path that may panic: #[thread_local]
static PANICKING: Cell<bool> = Cell::new(false);
// and then in on_panic instead of PANICKING.with(||{}) simply use it as regular static which contains a Cell. I’m mostly ignoring another thread_local LOCAL_STDERR here, because it can be retrieved later after we check for double panicking. |
I don’t exactly remember cases in which I could trigger it, but it certainly looks like this issue has been resolved by the linked PR. |
Implementation of
std::panicking::on_panic
may panic and not detect it is double-panicking, entering endless loop of panicking and overflowing stack.The text was updated successfully, but these errors were encountered: