Skip to content

Windows 服务(无控制台)环境下使用终端时 node-pty 反复崩溃:AttachConsole failed #112

Description

@Natura-a

Bug Report:终端在 Windows 服务环境下 node-pty AttachConsole failed 崩溃

环境

  • Windows 11 10.0.26200 (x64)
  • Node.js v24.19.0
  • dsh-better-sidebar 0.12.1(依赖 node-pty ^1.1.0
  • DSH web 以 Windows 服务运行(nssm,session 0,无交互控制台)

现象

  • 每次终端 spawn 后,node-pty 的 WindowsPtyAgent._getConsoleProcessList() fork conpty_console_list_agent.js,子进程 AttachConsole 失败,抛完整 Node 崩溃栈写入 ~/.dsh/logs/dsh-web.err.log
  • 单次运行可产生多次崩溃栈(实测历史日志 6 次),日志刷屏 + 反复 fork 进程。

崩溃栈

C:\Users\LENOVO\.dsh\profiles\web\node_modules\node-pty\lib\conpty_console_list_agent.js:13
var consoleProcessList = getConsoleProcessList(shellPid);
                         ^
Error: AttachConsole failed
    at Object.<anonymous> (conpty_console_list_agent.js:13:26)
    at Module._compile (node:internal/modules/cjs/loader:1872:14)
    ...
Node.js v24.19.0

触发场景

  • 宿主进程无控制台(Windows 服务 / 后台守护方式)时使用 node-pty 终端;DSH web 恰好以服务方式运行。

代码位置

  • node-pty/lib/windowsPtyAgent.js:140, 181-184:spawn 后调用 _getConsoleProcessList()child_process.fork(conpty_console_list_agent, [innerPid])
  • node-pty/lib/conpty_console_list_agent.js:13AttachConsole(shellPid) 失败未容错,直接抛错退出

建议

  1. node-pty 侧:AttachConsole 失败时降级(返回空列表 / 忽略),而不是崩溃退出。
  2. dsh-better-sidebar 侧:spawn 前检测宿主是否有控制台,或忽略 console 列表结果,避免在服务环境下 fork 该 agent。

AI 标识:本报告由 AI 辅助生成(ZCode · DeepSeek-V4),技术事实、代码行号与版本号经人工核实;提交前建议再自查一遍关键行号与版本号。

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1高:影响日常使用bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions