-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Nested panics and std::thread::panicking #143612
Copy link
Copy link
Open
Labels
A-panicArea: Panicking machineryArea: Panicking machineryI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-panicArea: Panicking machineryArea: Panicking machineryI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Should this abort? We often say that "double panics lead to abort", and I think we might even document that, but I've just found out this behavior is surprising to a lot of folks. So I want to ask for T-lang consensus: are double panics explicitly allowed if caught, and only unwinding across a landing pad leads to abort?
If double panics are allowed in this case, then everyone relying on
std::thread::panickingis subtly broken. We encounter the same problem asstd::uncaught_exceptionin C++. N4152 had to deprecatestd::uncaught_exceptionand expose a counter instead. I think N4152 explains the problem well enough, but the TL;DR for Rust is that it's impossible to reliably implement something likeScopeGuard, because we'll either notice a panic when there's none (becausestd::uncaught_exceptionis set at the beginning anyway), or ignore a panic when it does happen (which is a problem for e.g.MutexGuardcurrently, see #143471). I have found some unsoundness in the wild (1, 2, 3) due to this.I don't have a specific proposal to fix this, e.g. I don't think exposing
std::thread::panic_countis a good idea, but I at least want this problem to be known.@rustbot label +T-lang +T-libs-api +T-libs -C-discussion +A-panic