[wrangler] fix: report non-zero exit code when killed by a signal (e.g. OOM)#14598
[wrangler] fix: report non-zero exit code when killed by a signal (e.g. OOM)#14598matingathani wants to merge 1 commit into
Conversation
…g. OOM)
bin/wrangler.js's spawn().on("exit", ...) handler ignored the signal
argument entirely, treating a signal-killed child (code === null) the
same as a clean exit and calling process.exit(0). This made CI pipelines
believe wrangler succeeded when it was actually OOM-killed or otherwise
terminated by a signal. Now the signal is logged and the shim exits 1.
Fixes cloudflare#14584
🦋 Changeset detectedLatest commit: b84853f The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Wrangler’s wrapper executable (packages/wrangler/bin/wrangler.js) incorrectly reporting exit code 0 when the spawned CLI process is terminated by a signal (e.g. SIGKILL from OOM), which can cause CI/pipelines to treat failed runs as successful.
Changes:
- Add
resolveExitCode(code, signal)to treat signal-terminated child exits as failures and optionally log the terminating signal. - Update the child process
"exit"handler to useresolveExitCode()instead of treatingnullexit codes as success. - Add a unit test that directly exercises
resolveExitCode()without needing to spawn the full built CLI, plus a changeset entry for the patch release.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/wrangler/bin/wrangler.js | Adds resolveExitCode() and uses it to avoid reporting success when the child is killed by a signal. |
| packages/wrangler/src/tests/bin-wrangler-exit-code.test.ts | Unit tests for resolveExitCode() including signal-kill scenarios. |
| .changeset/fix-wrangler-signal-exit-code.md | Changeset documenting the behavioral fix and release impact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@cloudflare/autoconfig
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Fixes #14584
bin/wrangler.js(the actualwranglerexecutable) spawns the real CLI (wrangler-dist/cli.js) as a child process and forwards its exit code:Node's
exitevent fires withcode = nulland a populatedsignalwhen a child is killed by a signal instead of exiting normally. The handler above didn't even capturesignal, and treatedcode === nullas success — so any signal-killedwranglerprocess (OOM/SIGKILL as reported here, but also e.g. SIGTERM from an orchestrator timeout) silently reported exit code 0 to whatever invoked it, making CI pipelines believe the command succeeded. This applies to everywranglercommand, not justpages deploy.Root cause was found by the issue reporter (@QuentinFarizon) in the comments, including a proposed fix pattern.
Fix: capture
signal, and only treat the exit as clean when a real numericcodecame through. Otherwise log the signal to stderr and exit 1.To make this testable without spawning the full built CLI or relying on cross-platform signal delivery (SIGKILL semantics differ on Windows, which this repo's CI matrix covers), the exit-code decision is extracted into a small exported
resolveExitCode(code, signal)function that's unit tested directly. The file's actual CLI-spawning side effect is already guarded behindif (module === require.main), so requiring it from a test doesn't trigger a spawn.