#275 handle SIGTERM with graceful shutdown in entry.sh - #275
Open
VasilevNStas wants to merge 1 commit into
Open
Conversation
VasilevNStas
added a commit
to VasilevNStas/swarm-template
that referenced
this pull request
Jun 29, 2026
When the orchestrator (Docker, container scheduler, or manual cancel) sends SIGTERM to the container, entry.sh previously had no signal handler. The process was killed immediately — stdout was lost, and baza.rb could not distinguish between "job was cancelled" and "job disappeared due to infrastructure failure". This commit adds a trap on SIGTERM that: - Captures the elapsed wall time since entry.sh started - Prints "Job <id> terminated after <elapsed>s" to stdout - Exits with code 143 (128 + 15 = SIGTERM), the standard convention for signal-induced termination The orchestrator must send SIGTERM (not SIGKILL) for this to work, which is the default behaviour of Docker, Kubernetes, and most container runtimes.
VasilevNStas
force-pushed
the
275-sigterm-handler
branch
from
June 29, 2026 16:44
81380cb to
903b21d
Compare
Contributor
Author
|
@yegor256 — this PR is part of a 3-PR series that addresses a critical reliability gap in the baza.rb ↔ entry.sh pipeline. The problem: When baza.rb pushes a job, entry.sh runs judges update with no time limit, no convergence detection, and no signal handling. If judges hang or fail to converge, the container runs forever and baza.rb's polling of finished? times out after 10 minutes with no diagnostic information — the user sees a silent failure. |
When the orchestrator (Docker, container scheduler, or manual cancel) sends SIGTERM to the container, entry.sh previously had no signal handler. The process was killed immediately — stdout was lost, and baza.rb could not distinguish between "job was cancelled" and "job disappeared due to infrastructure failure". This commit adds a trap on SIGTERM that: - Captures the elapsed wall time since entry.sh started - Prints "Job <id> terminated after <elapsed>s" to stdout - Exits with code 143 (128 + 15 = SIGTERM), the standard convention for signal-induced termination The orchestrator must send SIGTERM (not SIGKILL) for this to work, which is the default behaviour of Docker, Kubernetes, and most container runtimes.
VasilevNStas
force-pushed
the
275-sigterm-handler
branch
from
June 29, 2026 16:55
903b21d to
da53658
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the orchestrator (Docker, container scheduler, or manual cancel) sends
SIGTERMto the container,entry.shcurrently has no signal handler. The process is killed immediately — stdout is lost, andbaza.rbcannot distinguish between "job was cancelled" and "job disappeared due to infrastructure failure".The problem
What this PR adds
"Job X terminated after Ys"+ exit 143finished? == yes,exit_code == 143Why exit 143?
Exit code 143 = 128 + 15 (SIGTERM). This is the POSIX shell convention: when a process is killed by signal N, the shell reports exit code 128+N. Using 143 allows
baza.rb(or any caller) to distinguish:Signal flow
SIGTERM→entry.shtrap firescleanup()prints diagnostic and callsexit 143Docker, Kubernetes, and most container runtimes send
SIGTERMfirst, thenSIGKILLafter a grace period. This trap handles the graceful phase.Checklist
bundle exec rubocop— 0 offensesbundle exec rake— all tasks pass@yegor256 please review