Repository navigation
0.2.1: keep the process alive until shutdown() settles - #6
Merged
Merged
Conversation
waitExit unref'd its grace timer, and opencode serve is unref'd too, so once a host had closed its own handles nothing held the event loop: the process exited before shutdown() settled. Code after `await shutdown()` never ran, a signal handler's own exit code was lost, and a process ignoring SIGTERM never got the SIGKILL. shutdown() is awaited explicitly, so holding the loop is its job; the timer is cleared as soon as every pending process has exited, so it holds the loop only while something is left to wait for. Two child-script tests pin it: a top-level `await shutdown()` and a SIGINT handler that closes its own timer first, each with a child that obeys SIGTERM and one that ignores it. The handler shape is the one that fails on Bun as well as Node.
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.
Why
Finding L-1 from the architect's review of #5. In 0.2.0,
waitExitunref'd its grace timer, andopencode serveis unref'd too. So once a host had closed its own handles, nothing held the event loop and the process exited beforeshutdown()settled:await shutdown()never ran;What
timer.unref()is removed fromwaitExit. The timer is cleared as soon as every pending process has exited, so the loop is held only while something is left to wait for. The longest it can be held isgraceMsplus 1 s, which the README now states.await shutdown();await shutdown(), then a log line, thenexit(130).Verified locally
verify:packok.unrefrestored, 4 tests go red on Node and 2 on Bun (the handler shape: the top-level shape does not trip Bun). With the fix, all are green.shutdown()with nothing pending, the process exits within ordinary runtime start-up time (about 100 to 280 ms), never after the 3 s grace.