Skip to content
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

Panics don't lock stderr while printing panic info #124995

Open
Ved-s opened this issue May 11, 2024 · 3 comments
Open

Panics don't lock stderr while printing panic info #124995

Ved-s opened this issue May 11, 2024 · 3 comments
Labels
A-panic Area: Panicking machinery C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Ved-s
Copy link

Ved-s commented May 11, 2024

Panics don't seem to lock stderr while printing, so if multiple threads panic at once, this will happen:

thread 'thread 'thread 'thread 'State runner 5 (sync)State runner 1 (sync)State runner 0 (sync)State runner 4 (sync)' panicked at ' panicked at ' panicked at ' panicked at src/circuits/relay.rssrc/circuits/relay.rssrc/circuits/relay.rssrc/circuits/relay.rs::::167167167167::9::9:
99:
not yet implemented:
:
not yet implemented
not yet implementednot yet implemented
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

As you can see, i forgot a todo!() in the code and 4 threads executed it at the same time

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (ccfcd950b 2024-04-15)
binary: rustc
commit-hash: ccfcd950b333fed046275dd8d54fe736ca498aa7
commit-date: 2024-04-15
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3
@Ved-s Ved-s added the C-bug Category: This is a bug. label May 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 11, 2024
@workingjubilee
Copy link
Contributor

hmm. I believe they do lock, as all instances of eprintln!("{}", message) do. but they then release the lock, and that causes the result you see. it's not clear that we should change the way it currently works by default. I know that rustc did it for its panic infrastructure, but rustc is a very opinionated Rust program.

@the8472
Copy link
Member

the8472 commented May 11, 2024

The panic hook creates a new stderr handle that does not lock

pub fn panic_output() -> Option<impl io::Write> {
Some(Stderr::new())
}

That's probably intentional to not deadlock during error reporting and to get last-gasp errors out as fast as possible. "probably" because I don't know the original motivation, but I think the current behavior is reasonable.

#122565 will coalesce more of the panic output writes into a single buffer, which will reduce tearing.

@workingjubilee
Copy link
Contributor

oh, okay! I stand corrected.

the manual-coalescing behavior done there does seem like a slightly better move than going for locking.

@saethlin saethlin added T-libs Relevant to the library team, which will review and decide on the PR/issue. A-panic Area: Panicking machinery C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. labels May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-panic Area: Panicking machinery C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants