Repository navigation
fix(dev): pass the shutdown timeout to the dev worker - #5137
stantheman0128 wants to merge 3 commits into
Conversation
The dev worker only bounds an open socket when the shutdown message includes a timeout.
An open socket keeps server.close pending unless the shutdown message includes a timeout. The worker then runs close hooks before the host gives up.
|
@stantheman0128 is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Neekoras
left a comment
There was a problem hiding this comment.
I traced the env-runner side, since the fix depends on it.
In env-runner 0.3.11, every process-based runner (node-worker, node-process, bun-process, deno-process) handles { event: "shutdown" } by calling shutdownWorker(server, entry, message.timeout). shutdownWorker races server.close() against timeout / 2 only when timeout is a number, and awaits it with no bound otherwise, then runs ipc.onClose. So without the field an open WebSocket keeps close() pending until the host's 5 s timer force-closes the worker, and with timeout: 5000 the worker stops waiting at 2.5 s and still runs onClose. That matches the 5,035 ms and 2,524 ms in #5133. The netlify and vercel runners have no shutdown handler and miniflare shuts down through its own dispose(), so they are unaffected.
Close hooks get the remaining 2.5 s of the host's budget, and env-runner is ^0.3.11 in package.json, so the field is always understood. src/dev/shutdown.ts is also the only place that sends the shutdown message, so nothing else needs the same change.
One optional suggestion: the test hardcodes 5000. Exporting SHUTDOWN_TIMEOUT and asserting against it would keep the test in step if the budget ever changes.
Export SHUTDOWN_TIMEOUT from src/dev/shutdown.ts so the unit test stays in step with the value the dev server sends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for tracing the env-runner side. On the hardcoded The constant stays internal. What I checked: I couldn't run vitest, lint or typecheck locally for this commit, since I don't have dependencies installed on this machine. I ran a small Node 24 script against Prepared with Claude Code. |
🔗 Linked issue
Resolves #5133
❓ Type of change
📚 Description
shutdownRunnerposted{ event: "shutdown" }and then waited 5 seconds for{ event: "exit" }. env-runner 0.3.11 only boundsserver.close()when that message includes a numerictimeout. Without it, an open response or WebSocket keepsserver.close()pending, the host timer force-closes the worker, andipc.onClosenever runs. The warning is:The shutdown message now includes
timeout: 5000, the same budget the host already uses. env-runner then stops waiting on the socket after 2.5 seconds and still runsipc.onClose.test/unit/dev-shutdown.test.tsfailed before the fix withexpected [ { event: 'shutdown' } ]and passed after it.test/unit/close-hooks.test.tsalso passed.Written with AI assistance (Cursor, Grok).
📝 Checklist