Skip to content

Linux:收到 SIGTERM 不退出 #39

Closed

Description

@Delta1035

现象

Linux 上向 DevHub 主进程发送 SIGTERM(kill <pid>)后,10 秒内仍不退出,只能 kill -9。1.3.0 与 1.4.0 的 AppImage 都能复现(Linux Mint 22.2,X11)。

影响

注销、关机、systemctl --user stop 等都会先发 SIGTERM:关机被拖慢;最终被强制结束(SIGKILL)时,before-quit 中停止进程树的逻辑(core.dispose())不会执行,正在运行的脚本可能成为孤儿进程。

复现

  1. 启动 DevHub(AppImage),不运行任何脚本
  2. kill -TERM <主进程 pid>
  3. 进程仍在运行

初步判断

apps/desktop/src/main/index.ts 没有处理 SIGTERM / SIGINT;退出依赖 before-quit。可能需要 process.on('SIGTERM', () => app.quit()),并确认与「关闭时最小化到托盘」的窗口 close 处理不冲突。修复需同时写 Linux 测试(AGENTS.md:进程管理两个平台都要测)。

发现于

#8(Linux AppImage 自动更新验证)

Activity

  1. added
    bugSomething isn't working
    area:desktopElectron 主进程、preload 与 renderer UI
    platform:linux只影响或需在 Linux 上验证
    on Oct 7, 2026
  2. Delta1035 commented on Oct 7, 2026

    @Delta1035
    OwnerAuthor

    修复见 #45。

    根因:没有运行中的脚本时,before-quit 里的 app.quit() 在 Electron 处理 SIGTERM 的 Quit() 内部重入(dispose() 在回调返回时的微任务中就完成了),外层用「被阻止」的结果覆盖了 is_quitting_;窗口关闭后 Electron 只发 window-all-closed,托盘模式下进程挂住。修复:把 app.quit() 推迟到下一轮事件循环。

    验证

    • Linux Mint 22.2(X11):1.4.0 AppImage 复现(40 秒未退出);源码构建加日志确认 before-quit ×2 → window-all-closed、没有 will-quit;修复后 before-quit → will-quit → quit,约 1 秒退出。
    • quit.spec.ts 新增 SIGTERM 用例(空闲退出、停止进程树;Windows 跳过):Linux 上全部通过,去掉修复后空闲用例超时失败。
    • Windows:pnpm check 通过;pnpm e2e 中一个无关的悬停卡片用例偶发失败,单独重跑通过。
    • 未验证:真实注销 / 关机。
  3. added a commit that references this issue on Oct 7, 2026
    28fb111
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

    area:desktopElectron 主进程、preload 与 renderer UIbugSomething isn't workingplatform:linux只影响或需在 Linux 上验证

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions