Repository navigation
fix(dispatcher): the in-process arm had no drain — its flag was never set - #590
Merged
Merged
Conversation
… set
`main.rs` passed `run_loop` a local `AtomicBool::new(false)` named `never`. The
name was accurate: nothing ever set it, so with `ER_DISPATCH_IN_PROCESS=1` the
dispatcher had no SIGTERM drain at all while the standalone `er-dispatcher`
did. `dispatcher_bin.rs`'s own header recorded the difference as a known gap.
**Two defects, and the second is the one that mattered.** Setting the flag is
only half a drain: the task is `tokio::spawn`ed, so `main` returning drops the
runtime and kills whatever the dispatcher was mid-way through — the exact
outcome the flag exists to prevent. So `main` now holds the `JoinHandle` and
awaits it after the server's own drain completes.
Unbounded on purpose: this path is only set by `frontend/dev/env.sh`, where
there is no kubelet to SIGKILL past a grace period and a process that exits
when both halves are done is what a developer wants. The deployed dispatcher is
its own Deployment with its own `terminationGracePeriodSeconds`.
`shutdown::sigterm_flag()` is the drain in both arms now rather than written
out twice — `on_sigterm()` is the shape `axum::serve` wants (a future), this is
the shape a loop wants (a value it polls at a boundary of its choosing). Same
signal, two shapes.
**Registering both in one process is safe, and the log proves it** rather than
the docs asserting it. `tokio::signal` hands every caller an independent stream
and a delivered signal wakes all of them:
16:18:49.938849 SIGTERM received; draining in-flight requests <- server
16:18:49.938849 SIGTERM received; draining the in-flight job <- dispatcher
16:18:49.939071 waiting for the in-process dispatcher to drain
16:18:49.999932 the dispatcher is draining and will exit
process exit=0
Same microsecond for both handlers, so neither consumed the signal from the
other. That last line could NOT have appeared before this change: with the flag
false forever the loop never took that branch, so its presence is the fix
working rather than a message that was always printed.
Also corrected two comments that this makes false, rather than leaving them to
mislead: `dispatcher_bin`'s header no longer warns about a difference that is
gone, and `main.rs` no longer claims the merged `web-api` service runs the
dispatcher in-process with a separate Deployment as "the alternative topology"
— the §6.7 split inverted that, and the chart has shipped a separate
`er-dispatcher` Deployment since.
Verified: `make check` green, plus the live SIGTERM run above against a
throwaway Postgres (`/readyz` 200 first, so the process was really serving when
it was signalled).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
main.rspassedrun_loopa localAtomicBool::new(false)namednever. The name was accurate: nothing ever set it, so withER_DISPATCH_IN_PROCESS=1the dispatcher had no SIGTERM drain at all, while the standaloneer-dispatcherdid.dispatcher_bin.rs's own header recorded the difference as a known gap.Two defects, and the second is the one that mattered
Setting the flag is only half a drain. The task is
tokio::spawned, somainreturning drops the runtime and kills whatever the dispatcher was mid-way through — the exact outcome the flag exists to prevent. Somainnow holds theJoinHandleand awaits it, after the server's own drain completes.Unbounded on purpose. This path is only set by
frontend/dev/env.sh: there's no kubelet here to SIGKILL past a grace period, and a process that exits when both halves are done is what a developer wants. The deployed dispatcher is its own Deployment with its ownterminationGracePeriodSeconds(#443).One drain, two shapes
shutdown::sigterm_flag()now serves both arms instead of being written out twice.on_sigterm()is the shapeaxum::servewants — a future. This is the shape a loop wants — a value it polls at a boundary of its own choosing, so it finishes the job in hand. Same signal, two shapes.Registering both in one process is safe, and the log proves it
Rather than asserting it from the docs —
tokio::signalhands every caller an independent stream and a delivered signal wakes all of them:Same microsecond for both handlers, so neither consumed the signal from the other.
And that last line could not have appeared before this change: with the flag false forever the loop never took that branch. Its presence is the fix working, not a message that was always printed.
Two comments corrected
Both became false, so they're fixed here rather than left to mislead:
dispatcher_bin's header no longer warns about a difference that's gone.main.rsno longer claims the mergedweb-apiservice runs the dispatcher in-process with a separate Deployment as "the alternative topology" — the §6.7 split inverted that, and the chart has shipped a separateer-dispatcherDeployment since.Verification
make checkgreen./readyzreturning 200 first so the process was genuinely serving when signalled.Last item of the blue/green plan.
🤖 Generated with Claude Code