fix(server): Sequence destroy() callback after native teardown - #1513
Open
RandomByte wants to merge 1 commit into
Open
fix(server): Sequence destroy() callback after native teardown#1513RandomByte wants to merge 1 commit into
RandomByte wants to merge 1 commit into
Conversation
Supervisor.destroy() passed the caller's callback to http.Server.close(), firing it on socket close. The BuildServer's teardown (the @parcel/watcher unsubscribe and the node:sqlite handle, which maps a 256 MB region of the database into memory) runs after that call and was not sequenced ahead of the callback, so server.close(resolve) resolved with SQLite still mid-close. The next test.serial opening a fresh DatabaseSync, or the worker exiting, then races the finalizing handle and raises an access violation on Windows (0xC0000005), surfacing as `exited with a non-zero exit code: 3221225477` in the reinitialize suite. Start the socket close, then await the definition watcher and BuildServer teardown, and await the socket last. The callback fires only once every native handle is closed.
RandomByte
marked this pull request as ready for review
August 7, 2026 09:57
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.
Fixes a unit test failing flakily in CI, most often on Node 22/24 on Windows, with
test/lib/server/reinitialize.js exited with a non-zero exit code: 3221225477. That code is0xC0000005, a native access violation on process teardown, not a test-assertion failure. The defect is in production teardown code, so the fix lands inSupervisor.js; the flaky reinitialize test is what surfaced it.Root cause
Supervisor.destroy() passed the caller's callback to http.Server.close(), firing it on socket close. The BuildServer's teardown (the
@parcel/watcherunsubscribe and the node:sqlite handle, which maps a 256 MB region of the database into memory) runs after that call and was not sequenced ahead of the callback, so server.close(resolve) resolved with SQLite still mid-close. The next test.serial opening a fresh DatabaseSync, or the worker exiting, then races the finalizing handle and raises an access violation on Windows (0xC0000005), surfacing asexited with a non-zero exit code: 3221225477in the reinitialize suite.Fix
Start the socket close, then await the definition watcher and BuildServer teardown, and await the socket last. The callback fires only once every native handle is closed.