`thread::scope` clobbers the panic payload
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::{panic::catch_unwind, thread};
fn main() {
let res = catch_unwind(|| {
thread::scope(|scope| {
scope.spawn(|| panic!("my panic message with useful information"));
});
});
let payload = res.unwrap_err();
let message = payload.downcast_ref::<&str>().unwrap();
dbg!(message);
}
I expected to see this happen: the panic payload from the scoped thread should be forwarded to the main thread using panic::resume_unwind. The payload passed to panic! inside the scope should be retrievable there, and there should not be any additional panics.
Instead, this happened: a second panic with no link to the original is caused by the thread::scope implementation, and the payload is a meaningless "a scoped thread panicked" message.
Meta
rustc --version --verbose:
rustc 1.85.1
beta and nightly also behave like this
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the std:🧵:scope implementation and reproduce the example using catch_unwind and panic::resume_unwind. Trace how the scoped thread's panic payload is handled; done means the original "my panic message with useful information" payload is recoverable on the main thread without an additional panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100