Skip to content

Commit e0ef0f2

Browse files
committed
Fixes an issue where errors do not get propogated correctly when the hypervisor handler thread returns an error.
The hypervisor handler thread can return an error rather than send a message, in this case the error returned would be a timeout rather than the real error, this change ensures that we check for an error in the hypervisor handler thread when we time out and return that if it exists Signed-off-by: Simon Davies <[email protected]>
1 parent ef066ad commit e0ef0f2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,30 @@ impl HypervisorHandler {
592592
HandlerMsg::Error(e) => Err(e),
593593
HandlerMsg::FinishedHypervisorHandlerAction => Ok(()),
594594
},
595-
Err(_) => Err(HyperlightError::HypervisorHandlerMessageReceiveTimedout()),
595+
Err(_) => {
596+
// If we have timed out it may be that the handler thread returned an error before it sent a message, so rather than just timeout here
597+
// we will try and get the join handle for the thread and if it has finished check to see if it returned an error
598+
// if it did then we will return that error, otherwise we will return the timeout error
599+
match self
600+
.execution_variables
601+
.join_handle
602+
.try_lock()
603+
.map_err(|_| HyperlightError::HypervisorHandlerMessageReceiveTimedout())?
604+
.take_if(|handle| handle.is_finished())
605+
{
606+
Some(handle) => {
607+
// If the thread has finished, we try to join it and return the error if it has one
608+
// we need to take ownership of the handle to join it
609+
610+
let res = handle.join();
611+
if res.as_ref().is_ok_and(|inner_res| inner_res.is_err()) {
612+
return Err(res.unwrap().unwrap_err());
613+
}
614+
Err(HyperlightError::HypervisorHandlerMessageReceiveTimedout())
615+
},
616+
None => Err(HyperlightError::HypervisorHandlerMessageReceiveTimedout()),
617+
}
618+
}
596619
}
597620
}
598621

0 commit comments

Comments
 (0)