1
Fork 0

Rollup merge of #137480 - fuzzypixelz:fix/124466, r=workingjubilee

Return unexpected termination error instead of panicing in `Thread::join`

There is a time window during which the OS can terminate a thread before stdlib can retreive its `Packet`. Currently the `Thread::join` panics with no message in such an event, which makes debugging difficult; fixes #124466.
This commit is contained in:
Matthias Krüger 2025-02-27 08:56:39 +01:00 committed by GitHub
commit f19d4b5f97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1739,7 +1739,16 @@ struct JoinInner<'scope, T> {
impl<'scope, T> JoinInner<'scope, T> {
fn join(mut self) -> Result<T> {
self.native.join();
Arc::get_mut(&mut self.packet).unwrap().result.get_mut().take().unwrap()
Arc::get_mut(&mut self.packet)
// FIXME(fuzzypixelz): returning an error instead of panicking here
// would require updating the documentation of
// `std::thread::Result`; currently we can return `Err` if and only
// if the thread had panicked.
.expect("threads should not terminate unexpectedly")
.result
.get_mut()
.take()
.unwrap()
}
}