Repository navigation
Keep serving for a while after SIGTERM (Config.shutdownDelayMs) - #8427
Conversation
There was a problem hiding this comment.
Superseded by the review of
085f652b.
This review, of f57bbf8b
💬 Approved with comments — The shutdown-delay logic looks correct and is well tested. The only note is an INFO about unrelated changes to MODULE.bazel.lock, including a hermetic_launcher downgrade.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
The shutdown-delay logic looks correct; MODULE.bazel.lock has unrelated changes.
Recommendation: 💬 Optional Nits
- [INFO] MODULE.bazel.lock has changes unrelated to the feature, including a hermetic_launcher downgrade from 0.0.17 to 0.0.16. (
MODULE.bazel.lock:145)
View full review
The timing logic is correct: the phases run in the right order, startup time counts towards the delay, a second SIGTERM ends the delay early, a zero delay drains at once, and /ready fails from the first signal on. The sigterm stream still waits forever when the signal handler cannot be installed, as the old code did.
MODULE.bazel.lock has changes unrelated to the feature: hermetic_launcher goes from 0.0.17 to 0.0.16, aspect_tools_telemetry goes from 0.5.1 to 0.5.2, and the yq.bzl usagesDigest changes. This looks like a lockfile regenerated against a different base.
✅ All other checks passed
🔒 Security: ✅ LGTM
The flag takes whole seconds as a u32. The change adds no new network endpoint, and a second SIGTERM always drains at once.
📖 AGENTS.md: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: f57bbf8b
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8427 +/- ##
==========================================
- Coverage 67.78% 67.75% -0.04%
==========================================
Files 848 848
Lines 215530 215648 +118
Branches 32508 32508
==========================================
+ Hits 146103 146105 +2
- Misses 50228 50343 +115
- Partials 19199 19200 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f57bbf8 to
085f652
Compare
There was a problem hiding this comment.
Superseded by the review of
f1199141.
This review, of 085f652b
✅ Approved — No issues found. The only earlier note, about unrelated lockfile changes, is resolved because the lockfile is no longer changed.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
The signal timing, the factory ownership at shutdown, listeners that end early, the zero delay and the end of the signal stream are all handled correctly. The tests cover the delay, a signal during startup, a second signal, and /ready answering 503 while Durable Objects stay served. MODULE.bazel.lock is no longer part of the diff.
⚡ Performance: ✅ LGTM
The delay adds one timer and one stream poll, only on the drain path. No per-request cost.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 085f652b
085f652 to
f119914
Compare
There was a problem hiding this comment.
Superseded by the review of
a6272134.
This review, of f1199141
✅ Approved — No issues found. The only earlier note, about unrelated lockfile changes, is resolved because the lockfile is no longer changed.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
The signal timing, the factory ownership at shutdown, listeners that end early, the zero delay and the end of the signal stream are all handled correctly. The tests cover the delay, a signal during startup, a second signal, and /ready answering 503 while Durable Objects stay served. MODULE.bazel.lock is no longer part of the diff.
⚡ Performance: ✅ LGTM
The delay adds one timer and one stream poll, only on the drain path. No per-request cost.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: f1199141 — same changes as 085f652b, so this is that commit's review (no new review was run; line numbers are as of 085f652b)
|
[AI] Fine with the feature, but I'd rather not add a CLI flag for it. Could it be a capnp field instead (top-level Separately: a node signalled before it serves was never ready, so it could skip the delay. That would remove the timestamped drain stream, |
f119914 to
a627213
Compare
|
Done, both points:
|
There was a problem hiding this comment.
Superseded by the review of
1db663d5.
This review, of a6272134
✅ Approved — No issues found in the changes since the last review: the config field, the environment variable and the signal handling during the delay all behave as described, and tests cover them.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
WORKERD_SHUTDOWN_DELAY_MS must be digits only, and both it and the config value are limited to one hour. A bad value ends the process at startup. /ready answering 503 does not change any access control.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
Startup signal check
In run.rs, a yield_now() followed by now_or_never() sees a SIGTERM that arrived during startup. No signal is lost before run polls.
Signal handling during the delay
The /ready guard is dropped on the first signal. The delay and a second signal are raced, and start_draining runs only afterwards, so stopTimeoutMs counts from the end of the delay.
Config value
with_shutdown_delay_environment checks the one-hour limit on the configured value. It reads the variable only when the field is 0, and it keeps the rest of the config when it rewrites the root. It runs before the deployments are applied, so a deployment that sets shutdownDelayMs is still refused.
Tests
The tests cover each of these paths.
⚡ Performance: ✅ LGTM
The delay adds one timer and one stream poll, only when the process is shutting down. Nothing is added per request.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: a6272134
a627213 to
1db663d
Compare
There was a problem hiding this comment.
Superseded by the review of
96685e52.
This review, of 1db663d5
💬 Approved with comments — The shutdown delay, the environment variable and the /ready handling all work as described, and tests cover them. The one note is an INFO: MODULE.bazel.lock is still changed in this pull request even though it has nothing to do with the feature.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
The feature code is correct and tested. One INFO: an unrelated lockfile change is still in the diff.
Recommendation: 💬 Optional Nits
- [INFO] MODULE.bazel.lock is still changed in this pull request (
usagesDigestand thewptarchive pin), although it is unrelated to shutdownDelayMs and the discussion says it was dropped. (MODULE.bazel.lock:408)
View full review
MODULE.bazel.lock is still in the diff (INFO)
The hermetic_launcher downgrade is gone. The file still changes the usagesDigest and moves the wpt archive from wpt-2e4dc257c to wpt-8ae17e423. That pin matches build/deps/gen/shared_deps.MODULE.bazel and build/deps/shared_deps.jsonc, so the change does no harm. It is still unrelated to this feature. The discussion says the lockfile was dropped from the branch, but it is still changed at this commit.
Code paths checked, no issues
run.rs: callingyield_now()and thennow_or_never()catches a SIGTERM that arrives during startup, so the drain starts at once. On the first signal the/readyguard is dropped. The delay then races a second signal, andstart_drainingruns only after that race, sostopTimeoutMsis counted from the end of the delay.entry.rs: if the signal handler cannot be installed, or the signal stream ends, thesigterm()stream waits forever instead of ending.cli/config.rs: the one-hour limit is checked on the value from the config. The environment variable is read only when the field is 0, and the rest of the config is kept when the root is rewritten.compose.rs: a deployment that setsshutdownDelayMsis refused, and a test covers this.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues. WORKERD_SHUTDOWN_DELAY_MS must be digits only, and the delay from either source is capped at one hour. Any invalid value stops the process at startup. Answering 503 on /ready does not change any access control.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
The change touches only startup and shutdown: one yield_now() at startup, then one timer and one stream poll at shutdown. Nothing runs per request, and nothing grows without bound.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 1db663d5
1db663d to
96685e5
Compare
There was a problem hiding this comment.
Superseded by the review of
ae40bb2f.
This review, of 96685e52
✅ Approved — No findings. The shutdown delay, the environment variable and the /ready handling work as described, tests cover them, and the unrelated lockfile change is gone.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues. WORKERD_SHUTDOWN_DELAY_MS must be digits only, and the delay is capped at one hour from either source. Any invalid value stops the process at startup. A deployment can't set the node's shutdown delay. The /ready change only makes the 503 start earlier.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
No issues found. MODULE.bazel.lock is no longer part of this pull request.
Code paths checked:
- Config and environment variable: the config value is capped at one hour. The variable is read only when the field is 0. A blank or unset variable leaves the config as it is, and the rest of the config is kept.
- Shutdown sequence: a SIGTERM during startup drains at once. With a delay of 0, draining starts directly after the signal.
stopTimeoutMsstarts counting when the delay ends. - Deployments: a deployment that sets
shutdownDelayMsis refused, and a test covers this.
⚡ Performance: ✅ LGTM
The change runs only at startup and shutdown. Nothing runs per request.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 96685e52
96685e5 to
ae40bb2
Compare
There was a problem hiding this comment.
Superseded by the review of
d89ef7aa.
This review, of ae40bb2f
💬 Approved with comments — No blocking or warning findings. One INFO: a non-UTF-8 WORKERD_CLUSTER_STOP_TIMEOUT_MS is silently ignored, while a non-UTF-8 WORKERD_SHUTDOWN_DELAY_MS ends the process at startup.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
Behaviour is correct and well tested; one minor inconsistency in how the two environment variables are read.
Recommendation: 💬 Optional Nits
- [INFO] A non-UTF-8 WORKERD_CLUSTER_STOP_TIMEOUT_MS is silently ignored, while a non-UTF-8 WORKERD_SHUTDOWN_DELAY_MS ends the process at startup. (
src/workerd/server/cli/config.rs:159)
View full review
WORKERD_CLUSTER_STOP_TIMEOUT_MS that is not valid UTF-8 is ignored (src/workerd/server/cli/config.rs:159, src/workerd/server/cli/lib.rs:551)
with_cluster gets its environment through an Env closure built with std::env::var(name).ok(). A value that is set but not UTF-8 therefore reaches milliseconds as None, and the config's stopTimeoutMs stays in effect with no message. with_shutdown_delay_environment reads its variable as an OsString, so it rejects the same input with "not UTF-8 text." The docs say that for both variables any value other than a whole number of milliseconds ends the process.
Checked and fine:
- A config without a cluster returns early, so no stop timeout is written into it.
- The delay is capped at an hour from either source, and blank values count as unset.
- A SIGTERM before serving drains at once, and a second SIGTERM cuts the delay short.
- A deployment that sets
shutdownDelayMsis refused, and a test covers that.
✅ All other checks passed
🔒 Security: ✅ LGTM
Both variables accept ASCII digits only, parse into u32 and are capped at an hour. A bad value fails at startup instead of falling back to a default. A configured delay above an hour is also rejected, and a deployment cannot set the node's shutdown delay.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
These changes run only at startup and shutdown. Nothing runs per request.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: ae40bb2f
ae40bb2 to
d89ef7a
Compare
There was a problem hiding this comment.
Superseded by the review of
37c64fd2.
This review, of d89ef7aa
💬 Approved with comments — No blocking or warning findings. The earlier UTF-8 inconsistency is fixed; one INFO about a doc comment that describes the environment override wrongly.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📝 Documentation: 💬 1 info
One doc comment describes the environment override inaccurately.
Recommendation: 💬 Optional Nits
- [INFO] with_environment doc comment says the environment only fills defaults, but WORKERD_SHUTDOWN_DELAY_MS overrides a configured delay. (
src/workerd/server/cli/lib.rs:515)
View full review
The doc comment on with_environment (src/workerd/server/cli/lib.rs:515-516) says it fills only the settings the config leaves at their defaults. with_shutdown_delay_environment (config.rs:194-198) takes the variable over the config's value whenever it is set.
✅ All other checks passed
🔒 Security: ✅ LGTM
Each variable accepts only a whole number of milliseconds, parsed into u32 and capped at an hour. A bad value ends the process at startup, and a non-UTF-8 cluster variable now does too. A deployment cannot set a node's shutdown delay.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
cluster_var (src/workerd/server/cli/lib.rs:531-540) treats an unset or empty variable as unset and ends the process on a non-UTF-8 value. with_cluster uses it for the stop timeout, key and bucket variables, so these variables now act the same way as WORKERD_SHUTDOWN_DELAY_MS.
⚡ Performance: ✅ LGTM
These changes run only at startup and shutdown.
Reviewed commit: d89ef7aa
d89ef7a to
37c64fd
Compare
A cloud load balancer in front of Kubernetes keeps sending new connections to a terminating pod for up to about 20 s, because endpoint removal propagates concurrently with SIGTERM. A node that drains at once refuses those connections; today a preStop sleep is the only way around that. * `Config.shutdownDelayMs` makes the first SIGTERM (Ctrl-Break on Windows) log one line and keep serving as before for that long, then run the existing drain unchanged. Listeners keep accepting, and a cluster node keeps its lease, membership and Durable Objects meanwhile. * A second SIGTERM during the delay starts the drain at once. * A SIGTERM that arrives while the server starts drains it as soon as it is up, without the delay: it was never ready, so nothing sends it traffic. * The default is 0, which drains at once, as before. * WORKERD_SHUTDOWN_DELAY_MS overrides the field for `serve`, for wrangler.json users, who never see the Cap'n Proto config, and for deployments that adjust a baked config. A binary from `workerd compile` carries the field and takes the variable when it runs, as `serve` does; `compile` never embeds the environment. * An empty variable counts as unset, leaving the config's delay, and trailing whitespace, such as a final newline, is trimmed. It must then hold digits only; a value that is not a whole number of milliseconds, or not UTF-8, ends the process at startup with an error that names it. * A delay above 3600000 ms (an hour), from the variable or, when that is unset, the config, ends the process at startup too. The delay waits out load balancers, which takes seconds, so a larger value is a unit mistake that would leave a stopping node serving for hours, and a cluster node killed by its supervisor before it hands its objects off. * A deployment that sets `shutdownDelayMs` is refused with an error that names the field, like the other node settings. * `ClusterConfig.stopTimeoutMs` runs from the end of the delay, so the supervisor's grace period must cover both; the schema and `serve --help` say so. `run::run` now takes the drain signals as a stream. Once the server has started, it yields to the runtime once and then checks whether a signal is pending. The yield matters: a start that never waits, such as one evaluating a large worker, can return without tokio ever having polled its drivers, so a signal from that time has not reached the stream yet. tokio's current_thread scheduler wakes a yielded task only after polling its drivers, signal handling included. The listeners then race `drain_due`, which waits for the first signal and the delay or a second signal, so a listener failing during the delay is still fatal. server-test.c++ drives the delay with the mock timer, configured through the field: the server serves through it and drains after it, a second signal cuts it short, and a signal sent before the server starts drains it without the timer advancing. cluster-test.mjs sends a real SIGTERM to a server whose worker keeps it starting for seconds and checks that it exits at once, which fails without the yield. The CLI's config tests cover the variable unset or blank, valid with and without trailing whitespace, overriding the config, unusable even over a configured delay, not UTF-8, and the cap on the config field; compose-test.rs covers the deployment.
During the shutdown delay a cluster node serves as before, but nothing should send it new traffic. Readiness is all that tells a Service or a load balancer health check so. * `GET /ready` on the cluster port answers 503 from the first SIGTERM on, through the delay, where it answered 200 until the drain began. Only readiness probes read it: peers route by lease records and draining announcements, so they keep reaching the node's Durable Objects meanwhile. Without a delay the drain starts at once, which already answered 503, so nothing changes there. * `ClusterNode::serving` and its guard become `ready` / `Ready`: the flag now means "takes traffic", not only "listeners are served". `drain_due` drops the guard on the first signal. * `Config.shutdownDelayMs`, `ClusterConfig` and `serve --help` say that `/ready` answers 503 during the delay. cluster-test.mjs checks, with WORKERD_SHUTDOWN_DELAY_MS, that a node with a 6 s delay answers 503 at once and keeps its lease and its DO, which runs there whether it is asked there or on the peer, then hands the DO off and leaves once the delay is over. Requests stop 2 s before the delay ends, and only those answered within it must have run on the stopping node, so a slow request cannot meet the handoff and fail the test. A node given a 600 s delay is still a member 2 s after the first SIGTERM, well after a drain would have left, and stops within the stop timeout of the second. Polling `/ready` is bounded by a per-request timeout and a deadline, so a missed signal fails the test.
There was a problem hiding this comment.
Superseded by the review of
8e3a148c.
This review, of 37c64fd2
💬 Approved with comments — No blocking findings. One WARNING: the new non-UTF-8 error path in cluster_var writes the WORKERD_CLUSTER_KEY value to stderr, so most of the key's characters can end up in pod logs.
Findings: 1 warning (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8427.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Security] `cluster_var` prints the raw value of a non-UTF-8 variable, including the secret `WORKERD_CLUSTER_KEY`, to stderr.
- **File:** src/workerd/server/cli/lib.rs:536
🔒 Security: ⚠️ 1 warning
The non-UTF-8 error in cluster_var writes the cluster key's value to stderr
Recommendation: 📝 Minor Comments
- [WARNING]
cluster_varprints the raw value of a non-UTF-8 variable, including the secretWORKERD_CLUSTER_KEY, to stderr. (src/workerd/server/cli/lib.rs:536)
View full review
cluster_var (src/workerd/server/cli/lib.rs:531-540) reads WORKERD_CLUSTER_KEY as well as the bucket and stop-timeout variables. When a value is not UTF-8, line 536 prints {name}={value} using to_string_lossy(). For the cluster key, every byte that is valid UTF-8 shows up verbatim in stderr, and stderr usually lands in container logs. A key pasted in as raw random bytes is the case most likely to hit this path.
The key-file path already handles this safely: read_key_file (config.rs:393) reports only that the file is not UTF-8, not its contents.
✅ All other checks passed
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
cluster_var (src/workerd/server/cli/lib.rs:531-540) treats a variable that is unset or empty as unset. A value that is not UTF-8 ends the process. with_cluster passes it only under --experimental, as it did the old closure. with_environment runs for serve and for a compiled binary, never for compile, so the environment is never embedded in a compiled config.
⚡ Performance: ✅ LGTM
These changes run only at startup and shutdown.
📝 Documentation: ✅ LGTM
The with_environment doc comment now says the environment overrides the config, which matches with_shutdown_delay_environment.
Reviewed commit: 37c64fd2
37c64fd to
8e3a148
Compare
There was a problem hiding this comment.
Superseded by the review of
3baa7a37.
This review, of 8e3a148c
💬 Approved with comments — Nothing blocks merging. One WARNING remains from the last review: if WORKERD_CLUSTER_KEY holds bytes that are not valid UTF-8, cluster_var prints most of the key to stderr, which usually ends up in pod logs.
Findings: 1 warning
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8427.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Security] `cluster_var` prints the value of a non-UTF-8 variable, including the secret `WORKERD_CLUSTER_KEY`, to stderr.
- **File:** src/workerd/server/cli/lib.rs:536
🔒 Security: ⚠️ 1 warning
cluster_var still prints the raw value of a non-UTF-8 WORKERD_CLUSTER_KEY to stderr.
Recommendation: 📝 Minor Comments
- [WARNING]
cluster_varprints the value of a non-UTF-8 variable, including the secretWORKERD_CLUSTER_KEY, to stderr. (src/workerd/server/cli/lib.rs:536)
View full review
- src/workerd/server/cli/lib.rs:535-536:
cluster_varreadsWORKERD_CLUSTER_KEY, the bucket variable and the stop-timeout variable. When a value is not valid UTF-8, it prints{name}={value}usingto_string_lossy(). For the cluster key, every byte that is valid UTF-8 appears as-is in stderr, and stderr usually goes to container logs. The key-file path already avoids this:read_key_filesays only that the file is not UTF-8 text. Printing just the variable name fixes it for all three variables.
✅ All other checks passed
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
No new issues since the last review. The stderr problem in cluster_var is covered in the security section.
⚡ Performance: ✅ LGTM
These changes only run at startup and shutdown.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 8e3a148c
8e3a148 to
3baa7a3
Compare
There was a problem hiding this comment.
Superseded by the review of
9369cdc1.
This review, of 3baa7a37
💬 Approved with comments — The earlier WARNING about the cluster key reaching stderr is fixed, and no new defects were found. One INFO remains: the lockfile change is unrelated to the feature.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
One INFO: MODULE.bazel.lock is back in the diff (it matches the declared capnproto pin).
Recommendation: 💬 Optional Nits
- [INFO] MODULE.bazel.lock is back in the diff (capnproto pin and usagesDigest), unrelated to the shutdown delay. (
MODULE.bazel.lock:436)
View full review
The two files changed since the last review, cli/lib.rs and MODULE.bazel.lock, were re-checked.
with_environmentruns in the compiled-binary path and inserve, beforewith_cluster, and not incompile. The environment therefore never ends up in compiled output.with_clustergetscluster_varas itsEnv. Its stop-timeout read gets the same non-UTF-8 handling as the other variables.MODULE.bazel.lockchanges the capnproto archive pin toee05f52. That matchesbuild/deps/gen/deps.MODULE.bazel:28-34, but the change is unrelated to this feature.
✅ All other checks passed
🔒 Security: ✅ LGTM
The NotUnicode(_) arm of cluster_var (src/workerd/server/cli/lib.rs:536-539) discards the value. It prints only {name}: not UTF-8 text. and exits. None of the cluster key, bucket or stop-timeout variables can leak a value this way. The values of the shutdown-delay and stop-timeout variables are bounded whole-number milliseconds and are not secret.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
⚡ Performance: ✅ LGTM
These changes only run at startup and shutdown.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 3baa7a37
A supervisor's grace period must cover the shutdown delay and the cluster's stop timeout together. The delay can be set in the environment, but a wrangler.json project, which has no Cap'n Proto config, had no way to set the stop timeout. Both timings now come from the same place. * `serve`, and a binary from `workerd compile`, take `ClusterConfig.stopTimeoutMs` from WORKERD_CLUSTER_STOP_TIMEOUT_MS when it is set, over the config's, as WORKERD_SHUTDOWN_DELAY_MS overrides `shutdownDelayMs`. That includes a cluster joined with `--cluster-addr`, since the variable is read in the same pass (`Config::with_cluster`). A config without a cluster is unchanged. * The variable is validated as WORKERD_SHUTDOWN_DELAY_MS is: blank counts as unset, trailing whitespace is trimmed, and anything but a whole number of milliseconds up to 3600000 (an hour) ends the process at startup, naming the variable. The two share one parser. * A cluster variable that is not UTF-8, this one or the key and bucket variables, now ends the process with an error that names it, as a non-UTF-8 WORKERD_SHUTDOWN_DELAY_MS does. It used to count as unset. * workerd.capnp, `serve --help` and AGENTS.md describe the variable. The CLI's config tests cover the variable overriding a default and a configured timeout, unset or blank, unusable, and applied to a joined cluster but not to a config without one. A non-UTF-8 value, which the tests cannot set, was checked by hand.
3baa7a3 to
9369cdc
Compare
There was a problem hiding this comment.
✅ Approved — No issues remain open. The unrelated lockfile change is gone, and the shutdown-delay, readiness and environment-variable handling look correct.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
For a non-UTF-8 value, cluster_var prints only the variable's name, never the value, so WORKERD_CLUSTER_KEY cannot reach stderr.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md issues found.
📋 Code Quality: ✅ LGTM
MODULE.bazel.lock is no longer in the diff.
What I checked:
- Signals:
sigterm()inentry.rsand the drain check inrun.rsbehave as their comments describe in three cases: a signal before the server serves, a second signal during the delay, and a handler that fails to install. - Readiness: cluster
/readyanswers 503 from the first SIGTERM on. - Stop timeout:
stopTimeoutMsruns from the end of the delay. - Environment:
with_environmentruns only on the serve and compiled-binary paths, never incompile. - Deployments:
compose.rsrefuses a deployment that setsshutdownDelayMs.
⚡ Performance: ✅ LGTM
These changes only run at startup and shutdown.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 9369cdc1
Behind a cloud load balancer, Kubernetes keeps sending new connections
to a terminating pod for up to about 20 s, because removing the
endpoint propagates at the same time as the SIGTERM. A workerd that
drains at once refuses them. Today the only fix is a
preStopsleep inthe manifest; this lets workerd cover it itself.
Config.shutdownDelayMs(default 0, which drains at once as before)makes the first SIGTERM log one line and keep serving for that long,
then run the existing drain unchanged.
WORKERD_SHUTDOWN_DELAY_MSoverrides the field when set, for wrangler.json users and for
deployments that adjust a baked config.
serve --helplists thevariable.
WORKERD_CLUSTER_STOP_TIMEOUT_MSlikewise overridesClusterConfig.stopTimeoutMs, also for a cluster joined with--cluster-addr, so the two timings that the grace period must coverare set in one place.
blank counts as unset, and anything else, a non-UTF-8 value included,
ends the process at startup with an error that names it. Non-UTF-8
cluster key and bucket variables now do too, as does a configured
delay above an hour. A deployment that sets
shutdownDelayMsisrefused.
through the delay.
/readyon the cluster port answers 503 from thefirst SIGTERM on. Only readiness probes read it; peers keep reaching
the node's objects.
ready, so nothing sends it traffic. A second SIGTERM during the delay
drains at once. SIGINT is not caught, so Ctrl-C still stops the
process immediately.
ClusterConfig.stopTimeoutMsruns from the end of the delay, so thegrace period must cover both: 20 s + 8 s fits in 40 s.
preStopsleep, objects first requested from the nodeduring the delay join its handoff at the end.
On a three-pod GKE demo with a 20 s delay and no
preStop, tworollouts served 801 and 845 requests, each on a new connection, with no
failures. Without
preStopthey failed 2 to 14 requests.The Kubernetes sample in #8274 still uses a
preStopsleep and canswitch to these variables once both have landed.
servehelp, AGENTS.mdComments in code files are counted with that file, except the
workerd.capnpcomments, which are the config reference, and the helptext.