1
Fork 0

Return error on unexpected termination 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:
Mahmoud Mazouz 2025-02-23 12:22:52 +01:00
parent bb2cc59a21
commit db1f0d0458
No known key found for this signature in database

View file

@ -1739,7 +1739,11 @@ 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()
if let Some(packet) = Arc::get_mut(&mut self.packet) {
packet.result.get_mut().take().unwrap()
} else {
Err(Box::new("thread terminated unexpectedly (e.g. due to OS intervention)"))
}
}
}