Skip to content

Commit

Permalink
Handle SIGINT (#434)
Browse files Browse the repository at this point in the history
This allows Ctrl+c killing the cas executable in environments that don't
invoke the it via a shell wrapper. This is the case in, for instance,
minimal container images.
  • Loading branch information
aaronmondal committed Dec 4, 2023
1 parent a0788fa commit f9e537c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
28 changes: 22 additions & 6 deletions Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "dc0784bec054d555c4643aca5880a90c3362bc82e90cf390b74f4eb467f72b65",
"checksum": "5c9608af6e959d25bdae4ff438bca27d04472bf9c473c0b131727c9e96e96c50",
"crates": {
"addr2line 0.21.0": {
"name": "addr2line",
Expand Down Expand Up @@ -7359,13 +7359,28 @@
"**"
],
"crate_features": {
"common": [
"default",
"std"
],
"common": [],
"selects": {
"aarch64-apple-darwin": [
"extra_traits"
"default",
"extra_traits",
"std"
],
"aarch64-unknown-linux-gnu": [
"default",
"std"
],
"arm-unknown-linux-gnueabi": [
"default",
"std"
],
"armv7-unknown-linux-gnueabi": [
"default",
"std"
],
"x86_64-unknown-linux-gnu": [
"default",
"std"
]
}
},
Expand Down Expand Up @@ -14229,6 +14244,7 @@
"process",
"rt",
"rt-multi-thread",
"signal",
"signal-hook-registry",
"socket2",
"sync",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ prometheus-client = "0.21.2"
rustls-pemfile = "1.0.3"
scopeguard = "1.2.0"
serde_json5 = "0.1.0"
tokio = { version = "1.29.1", features = ["rt-multi-thread"] }
tokio = { version = "1.29.1", features = ["rt-multi-thread", "signal"] }
tokio-rustls = "0.24.1"
tonic = { version = "0.9.2", features = ["gzip"] }
tower = "0.4.13"
7 changes: 7 additions & 0 deletions src/bin/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,5 +654,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.enable_all()
.on_thread_start(move || set_metrics_enabled_for_this_thread(metrics_enabled))
.build()?;

runtime.spawn(async move {
tokio::signal::ctrl_c().await.expect("Failed to listen to SIGINT");
eprintln!("User terminated process via SIGINT");
std::process::exit(130);
});

runtime.block_on(inner_main(cfg, server_start_time))
}

0 comments on commit f9e537c

Please sign in to comment.