Skip to content

Commit 94c1f83

Browse files
committed
feat(container-runner): log unexpected platform SIGTERM as an error
1 parent 58cfe9e commit 94c1f83

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

container-runner/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ static EXIT: LazyLock<CancellationToken> = LazyLock::new(CancellationToken::new)
7575
/// grace period instead).
7676
static SIGNAL_SHUTDOWN: AtomicBool = AtomicBool::new(false);
7777

78+
/// Set when shutdown was triggered by a platform SIGTERM (an instance reclaim),
79+
/// as opposed to a local SIGINT (developer Ctrl-C). Distinguishes a reclaim
80+
/// from a manual stop for downstream shutdown handling.
81+
static PLATFORM_RECLAIM: AtomicBool = AtomicBool::new(false);
82+
7883
/// How long the platform gives this container between SIGTERM and SIGKILL.
7984
/// Cloud Run defaults to 10 seconds (configurable up to 60 on the service);
8085
/// keep this in sync with the platform setting via RIVET_SIGTERM_BUDGET_SECS.
@@ -417,7 +422,12 @@ fn spawn_signal_handler() {
417422
let mut sigterm = signal(SignalKind::terminate()).expect("install SIGTERM handler");
418423
let mut sigint = signal(SignalKind::interrupt()).expect("install SIGINT handler");
419424
tokio::select! {
420-
_ = sigterm.recv() => tracing::info!("received SIGTERM"),
425+
_ = sigterm.recv() => {
426+
PLATFORM_RECLAIM.store(true, Ordering::Release);
427+
tracing::warn!(
428+
"unexpected platform SIGTERM received, likely hitting OOM or running longer than 60 minutes"
429+
);
430+
}
421431
_ = sigint.recv() => tracing::info!("received SIGINT"),
422432
}
423433
SIGNAL_SHUTDOWN.store(true, Ordering::Release);

0 commit comments

Comments
 (0)