Skip to content

[cli] run_listen missing SIGTERM handler — Docker Compose stop during testnet Grafana demo exits without graceful shutdown #253

@obchain

Description

@obchain

PR: #51 (feat/23-testnet-config)
File: crates/charon-cli/src/main.rs (run_listen tokio::select! block, line 180)
Refs #51

Problem

The tokio::select! in run_listen handles SIGINT only:

tokio::select! {
    _ = async { ... } => info!("all listeners exited"),
    _ = tokio::signal::ctrl_c() => info!("ctrl-c received, shutting down"),
}

docker stop sends SIGTERM (not SIGINT). kubectl delete pod sends SIGTERM. systemd stop sends SIGTERM. All of these terminate the Tokio runtime without running the shutdown branch — open WS connections are not closed, in-flight DashMap writes may be interrupted, Prometheus metrics server is killed mid-scrape.

First flagged in PR #30 review (finding 4). This PR's stated deployment context (Docker Compose for Grafana demo) makes SIGTERM handling load-bearing: the demo workflow is docker compose up / docker compose down, and down sends SIGTERM.

Impact

Ungraceful shutdown on every docker compose down cycle. Potential partial state in DashMap if scan is mid-upsert when SIGTERM arrives.

Fix

#[cfg(unix)]
{
    use tokio::signal::unix::{signal, SignalKind};
    let mut sigterm = signal(SignalKind::terminate())?;
    tokio::select! {
        _ = async { ... } => info!("all listeners exited"),
        _ = tokio::signal::ctrl_c() => info!("ctrl-c received, shutting down"),
        _ = sigterm.recv() => info!("sigterm received, shutting down"),
    }
}

tokio::signal::unix is Unix-only; wrap in #[cfg(unix)].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)priority:p1-coreCore MVP scopestatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions