-
Notifications
You must be signed in to change notification settings - Fork 98
fix(box_impl): offload blocking handler.stop() and metrics() to spawn_blocking #415
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,7 +50,7 @@ pub type SharedBoxImpl = Arc<BoxImpl>; | |||||||||||||||||||||||
| /// Separated from BoxImpl to allow operations like `info()` without initializing LiveState. | ||||||||||||||||||||||||
| pub(crate) struct LiveState { | ||||||||||||||||||||||||
| // VM process control | ||||||||||||||||||||||||
| handler: std::sync::Mutex<Box<dyn VmmHandler>>, | ||||||||||||||||||||||||
| handler: Arc<std::sync::Mutex<Box<dyn VmmHandler>>>, | ||||||||||||||||||||||||
| guest_session: GuestSession, | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Metrics | ||||||||||||||||||||||||
|
|
@@ -78,7 +78,7 @@ impl LiveState { | |||||||||||||||||||||||
| #[cfg(target_os = "linux")] bind_mount: Option<BindMountHandle>, | ||||||||||||||||||||||||
| ) -> Self { | ||||||||||||||||||||||||
| Self { | ||||||||||||||||||||||||
| handler: std::sync::Mutex::new(handler), | ||||||||||||||||||||||||
| handler: Arc::new(std::sync::Mutex::new(handler)), | ||||||||||||||||||||||||
| guest_session, | ||||||||||||||||||||||||
| metrics, | ||||||||||||||||||||||||
| _container_rootfs_disk: container_rootfs_disk, | ||||||||||||||||||||||||
|
|
@@ -294,11 +294,15 @@ impl BoxImpl { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let live = self.live_state().await?; | ||||||||||||||||||||||||
| let handler = live | ||||||||||||||||||||||||
| .handler | ||||||||||||||||||||||||
| .lock() | ||||||||||||||||||||||||
| .map_err(|e| BoxliteError::Internal(format!("handler lock poisoned: {}", e)))?; | ||||||||||||||||||||||||
| let raw = handler.metrics()?; | ||||||||||||||||||||||||
| let handler = Arc::clone(&live.handler); | ||||||||||||||||||||||||
| let raw = tokio::task::spawn_blocking(move || { | ||||||||||||||||||||||||
| let h = handler | ||||||||||||||||||||||||
| .lock() | ||||||||||||||||||||||||
| .map_err(|e| BoxliteError::Internal(format!("handler lock poisoned: {}", e)))?; | ||||||||||||||||||||||||
| h.metrics() | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| .await | ||||||||||||||||||||||||
| .map_err(|e| BoxliteError::Internal(format!("spawn_blocking join: {}", e)))??; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| .map_err(|e| BoxliteError::Internal(format!("spawn_blocking join: {}", e)))??; | |
| .map_err(|e| { | |
| BoxliteError::Internal(format!( | |
| "metrics spawn_blocking join (box_id={}): {}", | |
| self.config.id, e | |
| )) | |
| })??; |
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the handler mutex is poisoned, this path currently returns Ok(()) without attempting to stop the handler. That can leave the VM/shim running and leak resources. If the intent is to not fail shutdown on poisoning, consider recovering the guard via PoisonError::into_inner() and still calling stop(), while continuing to swallow the poisoning error itself.
| if let Ok(mut h) = handler.lock() { | |
| h.stop() | |
| } else { | |
| Ok(()) | |
| match handler.lock() { | |
| Ok(mut h) => h.stop(), | |
| Err(poisoned) => { | |
| tracing::warn!("Handler mutex poisoned during shutdown; recovering guard to stop handler"); | |
| let mut h = poisoned.into_inner(); | |
| h.stop() | |
| } |
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: the spawn_blocking join error message here doesn't indicate which operation failed. Adding context (e.g., stop spawn_blocking join) and/or the box_id would make operational debugging significantly easier.
| .map_err(|e| BoxliteError::Internal(format!("spawn_blocking join: {}", e)))??; | |
| .map_err(|e| { | |
| BoxliteError::Internal(format!( | |
| "stop spawn_blocking join (box_id={}): {}", | |
| self.config.id, e | |
| )) | |
| })??; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this raw not being used?