Repository navigation
fix(cli): exit when the event loop drains after the server probe (#1174) - #1179
Merged
Merged
Conversation
On Windows, Node.js 23 up to 24.19 / 26.6 can abort with a libuv UV_HANDLE_CLOSING assertion (nodejs/node#56645, fixed in 24.20.0 and 26.7.0) when process.exit() runs right after a fetch(). status, open, update and the error paths of stop did exactly that once a run record existed, so they exited 0xC0000409 despite correct output. Set process.exitCode and let the loop drain, with an unref'd 2 s process.exit() fallback, and drop the probe's response body so its connection is released before exit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
…gr#1174) (agegr#1179) On Windows, Node.js 23 up to 24.19 / 26.6 can abort with a libuv UV_HANDLE_CLOSING assertion (nodejs/node#56645, fixed in 24.20.0 and 26.7.0) when process.exit() runs right after a fetch(). status, open, update and the error paths of stop did exactly that once a run record existed, so they exited 0xC0000409 despite correct output. Set process.exitCode and let the loop drain, with an unref'd 2 s process.exit() fallback, and drop the probe's response body so its connection is released before exit. Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
…gr#1174) (agegr#1179) On Windows, Node.js 23 up to 24.19 / 26.6 can abort with a libuv UV_HANDLE_CLOSING assertion (nodejs/node#56645, fixed in 24.20.0 and 26.7.0) when process.exit() runs right after a fetch(). status, open, update and the error paths of stop did exactly that once a run record existed, so they exited 0xC0000409 despite correct output. Set process.exitCode and let the loop drain, with an unref'd 2 s process.exit() fallback, and drop the probe's response body so its connection is released before exit. Co-authored-by: Claude Opus 5.5 <[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.
Closes #1174.
Problem
On Windows,
pi-web status,open,updateand the error paths ofstopprinted the right output but exited with0xC0000409once a run record existed:bin/pi-web.jscalledprocess.exit(code)straight afterlistRunRecords()had probed each server withfetch(). That is nodejs/node#56645 (minimal repro in nodejs/node#58091). It affects Windows only, from Node 23 through 24.19 and 26.6, and is fixed by nodejs/node#61999, released in 24.20.0 and 26.7.0. The reporter runs 24.18.0.Change
bin/pi-web.js:exitWhenIdle(code)setsprocess.exitCodeand lets the event loop drain. An unref'd 2 s timer callsprocess.exit(code)only if something still holds the loop open. Both the success and error paths use it.bin/run-records.js:isServerAnswering()cancels the probe's response body, so its connection is released before exit. It is still a GET, and any HTTP status still counts, so a password-protected server answering 401 is still listed.Verification (macOS; Windows not available)
status,open,update --check, andstop --port N/open --port Nwith no match all keep their output and exit codes. They finish as quickly as before (status about 60 ms, update about 410 ms), with responses that are short, 1 MB, never-ending, or 401.lib/pi-web-cli-commands.test.mjs:statusagainst a real server on a temp port exits 0 on its own in under 1.5 s (about 95 ms here), so it doesn't rely on the fallback.tsc --noEmit, eslint, and the CLI tests pass.🤖 Generated with Claude Code