fix(settings): fall back to computed drain default on malformed SHUTDOWN_DRAIN_MS - #5177
Merged
Merged
Conversation
…OWN_DRAIN_MS resolveShutdownDrainMs passed SHUTDOWN_DRAIN_MS straight through Number() with no validation. A malformed value (typo, bad env injection) becomes NaN, and the sleep() helper silently treats NaN/negative delays as 0ms — skipping the shutdown drain the surrounding comment says exists specifically to outlast NLB deregistration and avoid CF 520s during rollout. Now an invalid override falls back to the computed per-role default instead of silently disabling the drain.
pedrofrxncx
enabled auto-merge (squash)
July 24, 2026 14:19
decocms Bot
pushed a commit
that referenced
this pull request
Jul 24, 2026
PR: #5177 fix(settings): fall back to computed drain default on malformed SHUTDOWN_DRAIN_MS Bump type: patch - decocms (apps/api/package.json): 4.122.9 -> 4.122.10 Deploy-Scope: server
This was referenced Jul 24, 2026
Merged
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.
Follows the same config-hardening lane as #5173 (NODE_ENV) and #5130 (DUCKDB_THREADS):
resolveShutdownDrainMsinapps/api/src/settings/resolve-config.tspassedSHUTDOWN_DRAIN_MSstraight throughNumber()with no validation.Why this matters: the function's own comment explains the drain exists to outlast NLB ip-target deregistration during rollout and avoid CF 520s on in-flight connections. A malformed override (typo, bad env injection, e.g.
SHUTDOWN_DRAIN_MS=abcor a negative value) becomesNaN/negative, and the sharedsleep()/delay()helper (packages/shared/src/std/delay.ts) silently collapses anyNaNor negative delay to 0ms — silently skipping the drain instead of erroring, reintroducing the exact 520 failure mode the drain was added to prevent.Fix: an invalid override now falls back to the computed per-role default (0 for
worker, ~60% of the force-exit budget otherwise) instead of silently becoming a 0ms no-op drain.Regression test: added two cases to the existing
resolveShutdownDrainMsdescribe block inresolve-config.test.ts— a non-numeric string and a negative number both now resolve to the computed default instead of 0.Reviewer command:
bun test apps/api/src/settings/resolve-config.test.tsChecks run locally:
bun run fmt,bunx tsc --noEmitinapps/api, and the targeted test file above (42 pass). Full CI validates the rest.Summary by cubic
Ensure the shutdown drain isn’t skipped when
SHUTDOWN_DRAIN_MSis malformed by falling back to a computed default instead of passing through a badNumber()result. This keeps drains active during rollouts and helps avoid CF 520s.SHUTDOWN_DRAIN_MSand only accept finite, non-negative values; otherwise use the per-role default (worker: 0ms, others: ~60% of force-exit).resolveShutdownDrainMs.Written for commit 0d4bd8a. Summary will update on new commits.