Shut down CompOS VM after compilation completes
Add a method to CompOsInstance to consume the instance and shut it
down cleanly, allowing logs to be written. Call this when compilation
ends, before calling back to our client (since they might then drop
their reference to us, which could tear everything down prematurely).
I also created a method to combind the calls to quit() and
wait_for_shutdown() to reduce duplication.
I also increased the shutdown timeout, since my initial value doesn't
seem to be enough for CompOS (see b/236588647#comment38).
Bug: 236581575
Test: composd_cmd test-compile, observe logs
Change-Id: I34a227db0e377cb9aded57461379e17d0574ea0c
diff --git a/compos/composd/src/odrefresh_task.rs b/compos/composd/src/odrefresh_task.rs
index 51e866f..07ede3c 100644
--- a/compos/composd/src/odrefresh_task.rs
+++ b/compos/composd/src/odrefresh_task.rs
@@ -49,7 +49,9 @@
impl ICompilationTask for OdrefreshTask {
fn cancel(&self) -> BinderResult<()> {
let task = self.take();
- // Drop the VM, which should end compilation - and cause our thread to exit
+ // Drop the VM, which should end compilation - and cause our thread to exit.
+ // Note that we don't do a graceful shutdown here; we've been asked to give up our resources
+ // ASAP, and the VM has not failed so we don't need to ensure VM logs are written.
drop(task);
Ok(())
}
@@ -95,27 +97,33 @@
let task = self.take();
// We don't do the callback if cancel has already happened.
- if let Some(task) = task {
+ if let Some(RunningTask { callback, comp_os }) = task {
+ // If we are the last owners of the instance (and we probably are), then we
+ // shut it down now, so that logs get written.
+ let comp_os = Arc::try_unwrap(comp_os);
+ // Make sure we keep our service alive until we have called the callback.
+ let lazy_service_guard = comp_os.map(CompOsInstance::shutdown);
+
let result = match exit_code {
Ok(ExitCode::CompilationSuccess) => {
info!("CompilationSuccess");
- task.callback.onSuccess()
+ callback.onSuccess()
}
Ok(exit_code) => {
let message = format!("Unexpected odrefresh result: {:?}", exit_code);
error!("{}", message);
- task.callback
- .onFailure(FailureReason::UnexpectedCompilationResult, &message)
+ callback.onFailure(FailureReason::UnexpectedCompilationResult, &message)
}
Err(e) => {
let message = format!("Running odrefresh failed: {:?}", e);
error!("{}", message);
- task.callback.onFailure(FailureReason::CompilationFailed, &message)
+ callback.onFailure(FailureReason::CompilationFailed, &message)
}
};
if let Err(e) = result {
warn!("Failed to deliver callback: {:?}", e);
}
+ drop(lazy_service_guard);
}
});
}