-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
#[track_caller] for std::sync::Once #87707
Comments
I think we could add it, we'd just need to run a perf test to make sure there are no obvious regressions, and adding it doesn't mean we won't remove it in the future if people come back and start complaining about the perf impact. |
It is worth noting that it seems at least plausible that this really wants to track the backtrace of the poisoning origin, not so much the (subsequent) access, right? In many cases this will overlap, of course. Something like #82271 might be worth considering as an expansion of this. |
@rustbot claim |
Could you please give me the sample code for this? |
Probably something like this: use std::sync::Once;
use core::panic::AssertUnwindSafe;
fn main() {
let o = Once::new();
let _ = std::panic::catch_unwind(AssertUnwindSafe(|| {
o.call_once(|| panic!("foo"));
}));
o.call_once(|| {});
} The first panic will still print a panic report before being caught and discarded, but the second call_once does subsequently observe the poisoned
If anything though this example makes me slightly less worried about the concern that @Mark-Simulacrum raised earlier. Even if we don't record the original location of the poisoning it should have an associated panic that got reported, so as long as the users haven't replaced the panic handler / hook with one that does no reporting they should be able to lookup where the original panic occurred, though it may not be particularly close to the subsequent poison panic in any outputted logs / stderr output. I'm curious what you think @Mark-Simulacrum , I suspect that this is probably good enough and that the only way we would be able to report the original poisoning location in the subsequent access would be to store the location in the |
@yaahc The code I noticed this with is this utility code in a test suite. The code initializes a sqlite3 environment in the testing process, and it simply panics on failure, as the tests are going to fail anyway from that point on. Minimizing the example boils down to what you posted. While the failure mode of
I concur that |
For sure, but this would only be available when you compile std yourself locally using |
…aahc Add #[track_caller] to track callers when initializing poisoned Once This PR is for this Issue. rust-lang#87707 With this fix, we expect to be able to track the caller when poisoned Once is initialized.
…aahc Add #[track_caller] to track callers when initializing poisoned Once This PR is for this Issue. rust-lang#87707 With this fix, we expect to be able to track the caller when poisoned Once is initialized.
closed by #94236 |
rust/library/std/src/sync/once.rs
Lines 390 to 393 in 3227e35
Trying to initialize a poisoned
Once
does not track it's caller, yielding panic messages likeCan we add
#[track_caller]
here? I've seen previous PRs regarding other performance-critical methods get rejected due to the overhead (?)track_caller
has.The text was updated successfully, but these errors were encountered: