Skip to content

Commit

Permalink
fix(shutdown): handle termination for container
Browse files Browse the repository at this point in the history
This commit handles incoming termination signal for tasks, ensuring
tasks are correctly terminated.

Signed-off-by: Radu Matei <[email protected]>
Co-authored-by: Rajat Jindal <[email protected]>
  • Loading branch information
2 people authored and kate-goldenring committed Mar 5, 2024
1 parent 6bfdbcb commit 77b383b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions containerd-shim-spin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ serde_json = "1.0"
url = "2.3"
anyhow = "1.0"
oci-spec = { version = "0.6.3" }
futures = "0.3"
ctrlc = { version = "3.2", features = ["termination"] }

17 changes: 16 additions & 1 deletion containerd-shim-spin/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,22 @@ impl SpinEngine {
}
};
info!(" >>> notifying main thread we are about to start");
f.await
let (abortable, abort_handle) = futures::future::abortable(f);
ctrlc::set_handler(move || abort_handle.abort())?;
match abortable.await {
Ok(Ok(())) => {
info!("Trigger executor shut down: exiting");
Ok(())
}
Ok(Err(err)) => {
log::error!("ERROR >>> Trigger executor failed: {:?}", err);
Err(err)
}
Err(aborted) => {
info!("Received signal to abort: {:?}", aborted);
Ok(())
}
}
}

async fn load_resolved_app_source(
Expand Down

0 comments on commit 77b383b

Please sign in to comment.