Repository navigation
Description
Summary
On Windows, commands that perform network requests can crash during process teardown with a libuv assertion:
Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76
Exit code 3221226505 (0xC0000409 / -1073740791; surfaced as 127 from Git Bash / MSYS).
The command's own output is still complete and correct (valid JSON, finish_reason=stop) — only the exit code is wrong, so batch/parallel scripts and CI that branch on $? record successful calls as failures.
This is not specific to DO_NOT_TRACK=1, and it did not start in 2.14.0 — see the corrections below.
Root cause
Two factors combined:
- Upstream Node.js bug (Windows,
v23.xandv24.0–v24.19):WorkerThreadsTaskRunner::DelayedTaskScheduler::Stop()closes theuv_async_t flush_tasks_handle without a shutdown guard, racing against V8 background worker threads (PostDelayedTask→uv_async_send) duringprocess.exit()teardown.- Issues: nodejs/node#56645, nodejs/node#58091
- Fix: nodejs/node#61999, backported to Node.js
v24.20.0(commit05ec9c4771)
bailian-clitrigger (sincev2.13.0, PR fix(runtime): flush tracked stdout/stderr before exit after run #348fix/exit-after-run): before 2.13.0,bailian.mjsended with.run()and let the event loop drain naturally (v2.12.0exits 0 even withDO_NOT_TRACK=1). PR fix(runtime): flush tracked stdout/stderr before exit after run #348 wrapped execution inrunToExit()and unconditionally callsprocess.exit(process.exitCode ?? 0)afterawait flushOutputs(null).
Corrections to the initial report
- The regression started in
v2.13.0, notv2.14.0. An earliernpm packtest of 2.13.0 exited 1 early on missing subpackages; full isolated installs confirmed2.12.0= exit 0,2.13.0= crash,2.14.0= crash. - Interactive runs do crash as well when
DO_NOT_TRACK=1is set (EXIT=-1073740791in PowerShell). They only appeared to pass earlier becauseDO_NOT_TRACKwas unset in that shell.
Triggers (either one is enough)
A. DO_NOT_TRACK=1
Without it, await flushTelemetry(1000) waits ~250–300 ms for the gm.mmstat.com request before process.exit(0), inadvertently acting as a grace delay past the < 50 ms post-fetch() race window. With DO_NOT_TRACK=1, telemetry short-circuits in 0 ms, so process.exit(0) runs ~0–1 ms after globalThis.fetch() completes. (On v24.10.0: a 0 ms or 10 ms delay before process.exit(0) crashed, while 50 ms+ passed 5/5.)
Original observation, Windows 10.0.26300 x64, node v24.10.0, bailian-cli 2.14.0 (npm global), spawned via execFile(node.exe, [bailian.mjs, ...]) with cwd: os.tmpdir(), windowsHide: true, DO_NOT_TRACK=1:
| command | with DO_NOT_TRACK=1 |
without |
|---|---|---|
--version |
ok | ok |
usage token-plan |
crash | ok |
console call --api zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage ... |
crash 6/6 runs | ok 6/6 runs |
--version survives because it never reaches the telemetry path; every command that emits telemetry crashes deterministically.
B. Proxy environment variables (no DO_NOT_TRACK involved) — still present in 2.18.1
Reported by @2010550zlt-gif on bl 2.18.1 / Node v24.19.0 / Windows 10.0.22631 x64 / Git Bash (MSYS), Token Plan cn-beijing. Same command, same key, only environment variables changed:
| environment variables | exit code | libuv assertion | [UNDICI-EHPA] warning |
stdout |
|---|---|---|---|---|
HTTPS_PROXY + HTTP_PROXY + ALL_PROXY all set |
127 | yes | yes | complete JSON |
only HTTP_PROXY + HTTPS_PROXY unset (ALL_PROXY kept) |
0 | no | no | complete JSON |
only HTTPS_PROXY kept |
127 | yes | yes | complete JSON |
| all unset | 0 | no | no | complete JSON |
# API key redacted
bl text chat --api-key [REDACTED] \
--base-url https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1 \
--model qwen3.8-flash --message "回复OK两个字符" \
--max-tokens 16 --enable-thinking false --timeout 120 --output jsonstderr of a failing run:
(node:NNNN) [UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental, expect them to change at any time.
Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 94
NO_PROXY='*'does not avoid it —blstill constructs anEnvHttpProxyAgentdispatcher and the assertion still fires.- Only commands that issue network requests are affected (
text chat/update/skill update/usage);bl config showandbl --versiondo not crash (EHPA warning only). - With
HTTPS_PROXY(orHTTP_PROXY) set and Node <v24.20.0, it reproduces every time on that host. - The assertion line varies by Node version:
src\win\async.c, line 76onv24.10.0,line 94onv24.19.0.
Reproduction scripts
1. bailian.mjs via execFile (matched cliEnvironment + DO_NOT_TRACK=1)
const { execFileSync } = require('child_process');
const os = require('os');
const mjs = 'C:\\path\\to\\bailian-cli\\dist\\bailian.mjs';
const allowed = new Set([
'PATH', 'Path', 'HOME', 'USERPROFILE', 'APPDATA', 'LOCALAPPDATA', 'SystemRoot', 'SYSTEMROOT',
'XDG_CONFIG_HOME', 'BAILIAN_CONFIG_DIR', 'LANG', 'LC_ALL', 'LC_CTYPE', 'TZ',
'HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'NO_PROXY',
'http_proxy', 'https_proxy', 'all_proxy', 'no_proxy',
]);
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => allowed.has(k)));
env.DO_NOT_TRACK = '1';
env.NO_UPDATE_NOTIFIER = '1';
execFileSync(
process.execPath,
[mjs, 'console', 'call', '--api', 'zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage', '--data', '{}', '--console-region', 'cn-beijing', '--console-site', 'domestic', '--output', 'json'],
{ cwd: os.tmpdir(), env, windowsHide: true, input: '', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] },
);2. Standalone pure-Node.js repros (no bailian-cli or credentials needed)
// Official nodejs/node#61999 regression test (no internet required)
require('http').createServer((_, res) => {
res.writeHead(302, { Location: '/' });
res.end();
}).listen(0, '127.0.0.1', async function() {
try { await fetch(`http://127.0.0.1:${this.address().port}/`); } catch {}
process.exit(0);
});// 4-line fetch + immediate process.exit(0)
(async () => {
const r = await fetch('https://bailian-cs.console.aliyun.com/');
await r.text();
process.exit(0);
})();Environment (original report)
- OS: Windows
10.0.26300x64 (16 CPUs) - Before upgrade:
node v24.10.0,npm 11.6.1 - After upgrade:
node v24.22.3,npm 11.19.1 - CLI install / entry: npm global (
node .../bailian-cli/dist/bailian.mjs, not Bunbl.exe);npm list -g bailian-cliis pinned at2.12.0, while2.13.0and2.14.0were tested from clean isolatednpm installdirectories. - Parent / config: reproduces under plain
node(execFile) and direct PowerShell (not Electron-specific). Default~/.bailian/config.json(no customBAILIAN_CONFIG_DIR), authenticated via AK/SK (access_key_id+access_key_secret, no consoleaccess_token), soconsole callexecutes two sequentialfetch()calls (modelstudio.cn-beijing.aliyuncs.com→bailian-cs.console.aliyun.com). - stderr of a failing run: stdout prints the complete valid JSON payload, stderr emits only
Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76.
Before / after verification
| Test case | Node v24.10.0 |
Node v24.22.3 (includes #61999) |
|---|---|---|
bailian-cli@2.12.0 + DO_NOT_TRACK=1 |
exit 0 |
— |
bailian-cli@2.13.0 + DO_NOT_TRACK=1 |
crash (0xC0000409, async.c:76) |
1/1 exit 0, valid JSON, empty stderr |
bailian-cli@2.14.0 + DO_NOT_TRACK=1 (stripped env) |
crash (0xC0000409, async.c:76) |
6/6 exit 0, valid JSON, empty stderr |
nodejs/node#61999 localhost 302 loop |
5/5 crash (async.c:76) |
5/5 exit 0 |
4-line fetch('https://bailian-cs.console.aliyun.com/') + process.exit(0) |
5/5 crash (async.c:76) |
5/5 exit 0 |
Independently confirmed by @2010550zlt-gif: Node v24.19.0 → v24.22.3 (official node-v24.22.3-x64.msi, SHA256 4a1ab5bdec5434bae58efae6c3e5077a011f6f1e76d2b47b7b10af043f7db545), same command with proxy variables kept, 3/3 exit 0, no libuv assertion, only the [UNDICI-EHPA] warning remains; bl unchanged at 2.18.1.
Expected
DO_NOT_TRACK=1should suppress telemetry without affecting the command's result or stability.- Proxy environment variables should not affect stability.
- The exit code should reflect the real result — today a fully successful request can still return non-zero, which breaks CI and agent scripts.
Workaround
Upgrade Node.js on Windows to >= v24.20.0 (verified with v24.22.3). This eliminates the crash completely on both trigger paths above.
Suggestions
- Document a Windows requirement of
Node >= v24.20.0(currentenginesonly states>=18.17.0), or emit a warning when Windows + Node <v24.20.0is detected. - In
runToExit, forceprocess.exit()only under Bun (process.versions.bun) and let Node.js exit naturally viaprocess.exitCode(asv2.12.0did). PR fix(runtime): flush tracked stdout/stderr before exit after run #348 addedprocess.exit()to avoid Bun's ~50 s keep-alive socket linger on Windows, which does not require forcing it on Node.js — Windows users still on Nodev23.x/v24.0–v24.19would then be protected without regressing Bun. - Make the exit code reflect the real result, e.g. wait for pending handles to close before exiting instead of racing a forced
process.exit().
Note on reproduction sensitivity
As documented in nodejs/node#56645, this race is highly sensitive to Windows build and thread scheduling — it reproduces 100% on Windows 11 Build 10.0.26300 while passing on some Windows Server 2025 / other Windows builds on the exact same Node version. This explains why the crash could not be reproduced deterministically on every host.
本 issue 由 Agent 工具总结提交;标题与正文已根据 @mamaruo 的根因定位与 @2010550zlt-gif 的代理变量复现路径修正、补充。
Activity
hopelynd commentedon Dec 1, 2026
Thanks for the report. We tried to reproduce this on Windows with the same setup described here and in token-monitor#1734 / PR #1753:
node …/dist/bailian.mjs)execFile(node, [bailian.mjs, …], { cwd: os.tmpdir(), windowsHide: true })DO_NOT_TRACK=1+NO_UPDATE_NOTIFIER=1console call --api zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage --data '{}' --console-region cn-beijing --console-site domestic --output jsonResult: 6/6 runs exited 0 and returned valid JSON. No
UV_HANDLE_CLOSING/0xC0000409.Interactive runs also do not crash (consistent with your note).
So we cannot reproduce a deterministic crash under the publicly described conditions. Marking this as needinfo.
If you still hit it, please share:
execFileoptions + env)node -v,npm -v,npm list -g bailian-cli, and whether PATH resolves to Bunbl.exeor the npmbailian.mjsentryBAILIAN_CONFIG_DIR, proxy, AV, etc.)Until we have a reliable repro, we won’t land a speculative fix for this issue alone. Downstream can keep the workaround of not forcing
DO_NOT_TRACK=1for background quota reads.mamaruo commentedon Dec 1, 2026
We tracked this down to an upstream Node.js Windows bug (nodejs/node#56645 / nodejs/node#58091), fixed in nodejs/node#61999 and backported to Node.js
v24.20.0(commit05ec9c4771), combined with the forcedprocess.exit()introduced inbailian-cli@2.13.0by #348. Upgrading local Node.js fromv24.10.0tov24.22.3completely eliminates the crash.Root Cause & Corrections to the Initial Report
v23.xandv24.0–v24.19on Windows):WorkerThreadsTaskRunner::DelayedTaskScheduler::Stop()closesuv_async_t flush_tasks_without a shutdown guard, racing against V8 background worker threads (PostDelayedTask->uv_async_send) duringprocess.exit()teardown and hittingAssertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76(0xC0000409).bailian-cliside trigger (v2.13.0, PR fix(runtime): flush tracked stdout/stderr before exit after run #348): Before2.13.0,bailian.mjsended with.run()and let the event loop drain naturally (v2.12.0exits 0 even withDO_NOT_TRACK=1). PR fix(runtime): flush tracked stdout/stderr before exit after run #348 (fix/exit-after-run) wrapped execution inrunToExit()and unconditionally calledprocess.exit(process.exitCode ?? 0)afterawait flushOutputs(null).v2.13.0, notv2.14.0(an earliernpm packtest of2.13.0exited 1 early on missing subpackages; full isolated installs confirmed2.12.0= exit 0,2.13.0= crash,2.14.0= crash).DO_NOT_TRACK=1is set (EXIT=-1073740791). Interactive runs only passed previously becauseDO_NOT_TRACKwas unset in the shell.Why
DO_NOT_TRACK=1Toggles It & Why Repro Varies Across Windows MachinesDO_NOT_TRACK=1acts as the switch: WithoutDO_NOT_TRACK=1,await flushTelemetry(1000)waits ~250–300 ms for thegm.mmstat.comrequest beforeprocess.exit(0), inadvertently acting as a grace delay past the< 50 mspost-fetch()race window (onv24.10.0, a 0 ms or 10 ms delay beforeprocess.exit(0)crashed, while 50 ms+ passed 5/5). WithDO_NOT_TRACK=1, telemetry short-circuits in 0 ms, soprocess.exit(0)executes ~0–1 ms afterglobalThis.fetch()completes.v24.10.0host: As documented innodejs/node#56645, this race is highly sensitive to Windows build and thread scheduling (for example, reproducing 100% on Windows 11 Build10.0.26300while passing on some Windows Server 2025 / other Windows builds on the exact same Node version).Requested Details
Minimal repro scripts
(a) Exact
bailian.mjsexecFilerepro (matchedcliEnvironment+DO_NOT_TRACK=1):(b) Standalone pure-Node.js repros (no
bailian-clior credentials needed):Full stderr of a failing run
Stdout prints the complete valid JSON payload, and stderr emits only:
Exit code:
3221226505(0xC0000409/-1073740791).Environment
10.0.26300x64 (16 CPUs)node v24.10.0,npm 11.6.1node v24.22.3,npm 11.19.1node .../bailian-cli/dist/bailian.mjs, not Bunbl.exe);npm list -g bailian-cliis pinned at2.12.0, while2.13.0and2.14.0were tested from clean isolatednpm installdirectories.Parent / config specifics
node(execFile) and direct PowerShell (not Electron-specific).~/.bailian/config.json(no customBAILIAN_CONFIG_DIR), authenticated via AK/SK (access_key_id+access_key_secret, no consoleaccess_token), soconsole callexecutes two sequentialfetch()calls (modelstudio.cn-beijing.aliyuncs.com->bailian-cs.console.aliyun.com).Before / After Verification
v24.10.0v24.22.3(includes#61999)bailian-cli@2.12.0+DO_NOT_TRACK=10bailian-cli@2.13.0+DO_NOT_TRACK=10xC0000409,async.c:76)0, valid JSON, empty stderrbailian-cli@2.14.0+DO_NOT_TRACK=1(stripped env)0xC0000409,async.c:76)0, valid JSON, empty stderrnodejs/node#61999localhost 302 loopasync.c:76)0fetch('https://bailian-cs.console.aliyun.com/') + process.exit(0)async.c:76)0Suggestion
PR #348 added
process.exit()specifically to avoid Bun's ~50s keep-alive socket linger on Windows. IfrunToExitonly forcesprocess.exit()under Bun (process.versions.bun) and lets Node.js exit naturally viaprocess.exitCode(likev2.12.0did), Windows users still on Nodev23.xorv24.0–v24.19would also be protected without regressing Bun. Otherwise, notingNode >= 24.20.0(orv22.x) on Windows is sufficient and this issue can be closed.本回复使用 Gemini 4 总结
2010550zlt-gif commentedon Dec 4, 2026
补充一条不依赖
DO_NOT_TRACK的复现路径,并确认该问题在 2.18.1 仍然存在。环境
base_url=https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1)DO_NOT_TRACK复现(同一命令、同一密钥,只改环境变量)
[UNDICI-EHPA]警告HTTPS_PROXY+HTTP_PROXY+ALL_PROXY都在HTTP_PROXY+HTTPS_PROXY(保留ALL_PROXY)HTTPS_PROXY(其余 unset)崩溃输出(stderr):
补充观察
NO_PROXY='*'不能规避:bl 仍会构造 EnvHttpProxyAgent dispatcher,断言照旧。text chat/update/skill update/usage);bl config show、bl --version不崩(仅 EHPA 警告)。finish_reason=stop,业务结果正确,只有退出码是假的。批量/并行脚本按$?判断会把成功调用记成失败(本机 4/5 次并行调用因此被误判)。process.exit();本机 Node v24.19.0 低于修复版本 v24.20.0。代理环境变量只是让这个 close-vs-async-send 竞态从偶发变成必现。HTTPS_PROXY(或HTTP_PROXY)且 Node < v24.20.0,必现。建议
engines只写>=18.17.0)。process.exit()与 pending async handle 竞争)。2010550zlt-gif commentedon Dec 4, 2026
确认 @mamaruo 的结论:本机升级 Node 后不再复现。
HTTPS_PROXY/HTTP_PROXY→ 每次text chat都在退出期断言(Git Bash 侧 exit 127)。node-v24.22.3-x64.msi,SHA2564a1ab5bdec5434bae58efae6c3e5077a011f6f1e76d2b47b7b10af043f7db545),同一命令、同样保留代理环境变量,3/3 exit 0、无 libuv 断言,finish_reason=stop;仅剩[UNDICI-EHPA]实验性警告。结论:在 Windows 上把 Node 升到 ≥ v24.20.0 即可规避,无需改动 CLI。建议在 README /
engines中标注该下限(当前engines只写>=18.17.0),否则 Windows + Node < v24.20.0 的用户会持续拿到「成功请求 + 非 0 退出码」的假失败。[-]DO_NOT_TRACK=1 crashes the CLI on Windows (libuv assertion, exit 0xC0000409) since 2.14.0[/-][+]Windows: libuv UV_HANDLE_CLOSING assertion crash on exit since 2.13.0 (upstream Node.js bug + forced process.exit())[/+]