Skip to content

Stop a build's run on SIGTERM and queue the build again at once - #209

Merged
ndbroadbent merged 1 commit into
mainfrom
processing-sigterm
Dec 4, 2026
Merged

ndbroadbent merged 1 commit into
mainfrom
processing-sigterm

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

When a rollout or a scale-down replaces a worker pod, Kubernetes sends SIGTERM. queue:work (laravel-rust 0.1.4) then stops taking jobs and waits for the running ones to finish. A large build's run outlasts the pod's grace period and gets killed part-way. Its build then sits until the processing lock's hold lapses and the sweep runs it again.

Now a ProcessBuild run starts a SIGTERM listener, once per process (domain::shutdown). The comparison loop checks the flag between snapshots. On SIGTERM the run stops and returns shutdown::Stopped. That releases the lock (exclusive returns), and run dispatches ProcessBuild again at once. The build stays processing and isn't failed. Another worker takes it straight away and processes it from the start. Comparing a snapshot again replaces its pages, so repeating comparisons is safe.

  • Only queue workers listen, because only the job installs the listener. A web pod's early comparisons are unaffected.
  • No grace period and no framework change: queue:work already lets the running job continue after SIGTERM, so our handler gets its turn.

Test: tests/shutdown.rs is its own binary, because it sets process-wide state. It sends a real SIGTERM to the test process, then runs the build. The run stops before comparing anything, the build stays processing, ProcessBuild is queued again (fake queue), and the lock is free straight away. A second run then finishes the build. With the check taken out of the loop, the test fails: the build completes in the stopped run.

Not covered here: the two-worker end-to-end test the plan mentioned (kill one of two real workers mid-build). This test checks the same behaviour inside one process.

docs/design-storage.md describes the behaviour, next to the processing lock.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@visualci-com

visualci-com Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #771 · 521 unchanged · no changes

This PR vs base: 9 changed since #729, across 2 builds

docspring/visualci · journeys · build #769 · 50 unchanged · no changes

This PR vs base: 1 changed since #738, across 2 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

@ndbroadbent
ndbroadbent merged commit cef3337 into main Dec 4, 2026
16 checks passed
@ndbroadbent
ndbroadbent deleted the processing-sigterm branch December 4, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant