Skip to content

DO_NOT_TRACK=1 crashes the CLI on Windows (libuv assertion, exit 0xC0000409) since 2.14.0 #356

Backlog

Description

@mamaruo

Summary

Since bailian-cli 2.14.0, setting DO_NOT_TRACK=1 in the environment makes every real command crash with a libuv assertion. Embedders that run the CLI headlessly (background quota readers, schedulers) commonly set this variable, so 2.14.0 breaks them.

Reproduction

Windows 10.0.26300 x64, node v24.10.0, bailian-cli 2.14.0 (npm global). Spawn 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

Crash output:

Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76

exit code 3221226505 (0xC0000409). --version survives because it never reaches the telemetry path; every command that emits telemetry crashes deterministically, so this looks like a close-vs-async-send race in the telemetry submission path (libuv uv_async_send on a closing handle) rather than a network failure.

2.13.0 did not have this behavior (background readers worked with the same environment).

Expected

DO_NOT_TRACK=1 should suppress telemetry without affecting the command's result or stability

本issue由Agent工具总结提交

Activity

  1. added
    question
    on Dec 1, 2026
  2. hopelynd commented on Dec 1, 2026

    @hopelynd
    Collaborator

    Thanks for the report. We tried to reproduce this on Windows with the same setup described here and in token-monitor#1734 / PR #1753:

    • Windows + Node v24.10.0
    • bailian-cli@2.14.0 (npm global, node …/dist/bailian.mjs)
    • execFile(node, [bailian.mjs, …], { cwd: os.tmpdir(), windowsHide: true })
    • stripped child env (allowlisted vars only) + DO_NOT_TRACK=1 + NO_UPDATE_NOTIFIER=1
    • stdin closed
    • command:
      console call --api zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage --data '{}' --console-region cn-beijing --console-site domestic --output json

    Result: 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:

    1. Exact minimal repro script (full execFile options + env)
    2. Full stderr of a failing run
    3. node -v, npm -v, npm list -g bailian-cli, and whether PATH resolves to Bun bl.exe or the npm bailian.mjs entry
    4. Whether anything else is special in the parent process (Electron, custom BAILIAN_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=1 for background quota reads.

  3. mamaruo commented on Dec 1, 2026

    @mamaruo
    Author

    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 (commit 05ec9c4771), combined with the forced process.exit() introduced in bailian-cli@2.13.0 by #348. Upgrading local Node.js from v24.10.0 to v24.22.3 completely eliminates the crash.

    Root Cause & Corrections to the Initial Report

    • Underlying Node.js bug (v23.x and v24.0–v24.19 on Windows): WorkerThreadsTaskRunner::DelayedTaskScheduler::Stop() closes uv_async_t flush_tasks_ without a shutdown guard, racing against V8 background worker threads (PostDelayedTask -> uv_async_send) during process.exit() teardown and hitting Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76 (0xC0000409).
    • bailian-cli side trigger (v2.13.0, PR fix(runtime): flush tracked stdout/stderr before exit after run #348): Before 2.13.0, bailian.mjs ended with .run() and let the event loop drain naturally (v2.12.0 exits 0 even with DO_NOT_TRACK=1). PR fix(runtime): flush tracked stdout/stderr before exit after run #348 (fix/exit-after-run) wrapped execution in runToExit() and unconditionally called process.exit(process.exitCode ?? 0) after await flushOutputs(null).
    • Correction 1 (version): The regression started in v2.13.0, not v2.14.0 (an earlier npm pack test of 2.13.0 exited 1 early on missing subpackages; full isolated installs confirmed 2.12.0 = exit 0, 2.13.0 = crash, 2.14.0 = crash).
    • Correction 2 (interactive runs): Direct PowerShell runs do also crash when DO_NOT_TRACK=1 is set (EXIT=-1073740791). Interactive runs only passed previously because DO_NOT_TRACK was unset in the shell.

    Why DO_NOT_TRACK=1 Toggles It & Why Repro Varies Across Windows Machines

    • Why DO_NOT_TRACK=1 acts as the switch: Without DO_NOT_TRACK=1, 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 (on v24.10.0, a 0 ms or 10 ms delay before process.exit(0) crashed, while 50 ms+ passed 5/5). With DO_NOT_TRACK=1, telemetry short-circuits in 0 ms, so process.exit(0) executes ~0–1 ms after globalThis.fetch() completes.
    • Why 6/6 passed on your Windows + v24.10.0 host: As documented in nodejs/node#56645, this race is highly sensitive to Windows build and thread scheduling (for example, reproducing 100% on Windows 11 Build 10.0.26300 while passing on some Windows Server 2025 / other Windows builds on the exact same Node version).

    Requested Details

    1. Minimal repro scripts

      (a) Exact bailian.mjs execFile repro (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'] },
      );

      (b) 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);
      })();
    2. Full stderr of a failing run

      Stdout prints the complete valid JSON payload, and stderr emits only:

      Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76
      

      Exit code: 3221226505 (0xC0000409 / -1073740791).

    3. Environment

      • OS: Windows 10.0.26300 x64 (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 Bun bl.exe); npm list -g bailian-cli is pinned at 2.12.0, while 2.13.0 and 2.14.0 were tested from clean isolated npm install directories.
    4. Parent / config specifics

      • Reproduces under plain node (execFile) and direct PowerShell (not Electron-specific).
      • Default ~/.bailian/config.json (no custom BAILIAN_CONFIG_DIR), authenticated via AK/SK (access_key_id + access_key_secret, no console access_token), so console call executes two sequential fetch() calls (modelstudio.cn-beijing.aliyuncs.com -> bailian-cs.console.aliyun.com).

    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

    Suggestion

    PR #348 added process.exit() specifically to avoid Bun's ~50s keep-alive socket linger on Windows. If runToExit only forces process.exit() under Bun (process.versions.bun) and lets Node.js exit naturally via process.exitCode (like v2.12.0 did), Windows users still on Node v23.x or v24.0–v24.19 would also be protected without regressing Bun. Otherwise, noting Node >= 24.20.0 (or v22.x) on Windows is sufficient and this issue can be closed.

    本回复使用 Gemini 4 总结

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions