-
Notifications
You must be signed in to change notification settings - Fork 13.8k
fix interleaved output in the default panic hook when multiple threads panic simultaneously #127397
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
Conversation
rustbot has assigned @workingjubilee. Use |
I suspect this is more due to us having needed to internalize, as much as possible, the horrible details of backtraces. |
I also suspect that in practice, backtraces on Windows are actually much more tame now due to us using |
Yes and no. Symbolization is still a problem area. The APIs we're using are designed to be run from an external "debugger" process and not in-process. |
i did find a mutex in windows that looks like it takes care of the multi-threading issues for us: https://github.com/rust-lang/backtrace-rs/blob/72265bea210891ae47bbe6d4f17b493ef0606619/src/dbghelp.rs#L283-L376 |
Yeah, we need a special process-wide mutex so that it works if multiple Rust DLLs are in the same process (doesn't help if another language or library uses these functions though). |
that sounds fine, tbh. "randomly-included C code" can't coordinate perfectly on this, so we can't either, and our responsibility is discharged by doing the best we can. |
5ce6bb0
to
875b730
Compare
lol apparently some test runners set RUST_BACKTRACE=1 on globally? no idea why |
875b730
to
ae92d6a
Compare
Ah, I really should have remembered and asked for @bors r- |
could you mark this as rollup=iffy? |
previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook would be interleaved with the backtrace. now, we hold the lock for the full duration of the hook, and the output is ordered.
3a1dd85
to
1c8f9bb
Compare
yeah. @bors rollup=iffy r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0065384): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary -0.0%, secondary -0.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 706.568s -> 706.526s (-0.01%) |
congrats to @rust-lang/wg-compiler-performance, this is a really impressively low amount of noise |
previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook from one thread would be interleaved with the backtrace from another. now, we hold the lock for the full duration of the hook, and the output is ordered.
i noticed some odd things while working on this you may or may not already be aware of.
cfg(backtrace_in_std)
instead of a more normalcfg(feature = "rustc-dep-of-std")
. probably this is left over from before rust used a cargo-based build system?trace_unsynchronized
, etc, insys::backtrace::print
. as a result, the lock only applies to concurrent panic handlers, not concurrent threads. in other words, if another, non-panicking, thread tried to print a backtrace at the same time as the panic handler, we may have UB, especially on windows.backtrace_in_std
is set so we can reuse their lock instead of trying to add our own.