Skip to content

Restore Windows exit delay and setBlocking workarounds#138

Closed
silverwind wants to merge 3 commits into
masterfrom
fix-node24-windows-dispatcher
Closed

Restore Windows exit delay and setBlocking workarounds#138
silverwind wants to merge 3 commits into
masterfrom
fix-node24-windows-dispatcher

Conversation

@silverwind

@silverwind silverwind commented May 10, 2026

Copy link
Copy Markdown
Owner

The Symbol-based dispatcher.close() approach relied on a private Node API and didn't reliably fix the Node 24 Windows flake. Going back to the straightforward 200ms-on-Windows delay (up from the original 50ms — community minimum is 100ms+, doubled for headroom) and the stdio setBlocking workaround — honest about the upstream Node bug, no reaching into internals.

Refs nodejs/node#56645


This PR was written with the help of Claude Opus 4.7

Aborting the prewarms isn't enough — the keep-alive socket pool still
has idle handles that race during natural shutdown on Windows + Node 24
(nodejs/node#56645). Closing the global dispatcher drains the pool
cleanly, eliminating the race.

Node exposes the global dispatcher via Symbol.for("undici.globalDispatcher.1");
this is the same mechanism undici itself uses to share it with the
runtime.

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@silverwind

Copy link
Copy Markdown
Owner Author

Switching to a simpler workaround approach — see follow-up.

@silverwind silverwind closed this May 10, 2026
@silverwind silverwind reopened this May 10, 2026
The Symbol-based dispatcher.close workaround relied on a private Node API
and didn't reliably fix the Node 24 Windows flake. Restoring the
straightforward 100ms-on-Windows delay and the stdio setBlocking
workaround is honest about the upstream Node bug and avoids reaching
into internals.

Refs nodejs/node#56645

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@silverwind silverwind changed the title Drain undici dispatcher before exit to fix Node 24 Windows race Restore Windows exit delay and setBlocking workarounds May 10, 2026
Refs nodejs/node#56645

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@silverwind

Copy link
Copy Markdown
Owner Author

Reverted #137 on master instead. See nodejs/node#56645 — this can only be fixed in Node itself.

@silverwind silverwind closed this May 10, 2026
@silverwind silverwind deleted the fix-node24-windows-dispatcher branch May 10, 2026 22:44
mickey-mikey added a commit to mickey-mikey/ai-inference that referenced this pull request May 24, 2026
…rash

On Windows, the explicit process.exit() calls in run() abort with
  Assertion failed: !(handle->flags & UV_HANDLE_CLOSING),
  file src\win\async.c, line 76
when the openai SDK's undici-based HTTP/2 connection pool is still
tearing down the TLS socket to models.github.ai. This is the upstream
Node bug tracked at nodejs/node#56645 — Node calls uv_async_send() on
an async handle after uv_close(), which libuv asserts against. The
upstream fix (nodejs/node#61999) has been stalled in review since
January 2025, and no released Node version contains it yet.

Reproduces 100% of the time against models.github.ai on Windows Node 24
with the openai SDK; passes 100% with a brief setTimeout before exit.
Same workaround already shipped by astral-sh/setup-uv (#880, 100ms) and
silverwind/updates (actions#138, 200ms).

Extract a `safeExit(code)` helper that yields for 100ms on Windows only
before calling process.exit; Linux and macOS take the original code
path with no added latency.

Refs:
- nodejs/node#56645
- astral-sh/setup-uv#880
- silverwind/updates#138
mickey-mikey added a commit to mickey-mikey/ai-inference that referenced this pull request May 24, 2026
…rash

On Windows, the explicit process.exit() calls in run() abort with
  Assertion failed: !(handle->flags & UV_HANDLE_CLOSING),
  file src\win\async.c, line 76
when the openai SDK's undici-based HTTP/2 connection pool is still
tearing down the TLS socket to models.github.ai. This is the upstream
Node bug tracked at nodejs/node#56645 — Node calls uv_async_send() on
an async handle after uv_close(), which libuv asserts against. The
upstream fix (nodejs/node#61999) has been stalled in review since
January 2025, and no released Node version contains it yet.

Reproduces 100% of the time against models.github.ai on Windows Node 24
with the openai SDK; passes 100% with a brief setTimeout before exit.
Same workaround already shipped by astral-sh/setup-uv (#880, 100ms) and
silverwind/updates (actions#138, 200ms).

Extract a `safeExit(code)` helper that yields for 100ms on Windows only
before calling process.exit; Linux and macOS take the original code
path with no added latency.

Refs:
- nodejs/node#56645
- astral-sh/setup-uv#880
- silverwind/updates#138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant