Skip to content
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

Fix windows sigterm handling #1174

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions crates/torii/server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ use sqlx::SqlitePool;
use starknet::core::types::FieldElement;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use tokio::signal::ctrl_c;
#[cfg(target_family = "unix")]
use tokio::signal::unix::{signal, SignalKind};
#[cfg(target_family = "windows")]
use tokio::signal::windows::{ctrl_c, CtrlBreak};
use tokio::sync::broadcast;
use tokio::sync::broadcast::Sender;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -81,15 +80,12 @@ async fn main() -> anyhow::Result<()> {
// Setup cancellation for graceful shutdown
let (shutdown_tx, _) = broadcast::channel(1);

let sigint = ctrl_c();

#[cfg(target_family = "unix")]
let mut sigterm = signal(SignalKind::terminate())?;
#[cfg(target_family = "unix")]
let mut sigint = signal(SignalKind::interrupt())?;

#[cfg(target_family = "windows")]
let mut sigterm = ctrl_c()?;
#[cfg(target_family = "windows")]
let mut sigint = CtrlBreak::new()?;
let (_, sigterm) = futures::channel::mpsc::unbounded::<()>();

let database_url = format!("sqlite:{}", &args.database);
let options = SqliteConnectOptions::from_str(&database_url)?.create_if_missing(true);
Expand Down Expand Up @@ -157,7 +153,7 @@ async fn main() -> anyhow::Result<()> {
_ = sigterm.recv() => {
let _ = shutdown_tx.send(());
}
_ = sigint.recv() => {
_ = sigint => {
let _ = shutdown_tx.send(());
}

Expand Down
Loading