Repository navigation
fix(desktop): quit on SIGTERM when no scripts are running - #45
Merged
Merged
Conversation
With nothing to stop, core.dispose() settles within the microtasks Node drains as the before-quit handler returns. On SIGTERM Electron calls Browser::Quit() from a task with no JS on the stack, so the follow-up app.quit() re-entered Quit() before the outer call stored its result; the outer, prevented result then reset is_quitting_. The windows still closed, Electron saw "all windows closed" without quitting, and DevHub stayed alive with its tray destroyed, so logout and shutdown had to SIGKILL it. Defer the follow-up quit to the next event loop turn. Add Linux/macOS E2E tests for SIGTERM, idle and with a running process tree; the idle one times out without the fix. Closes #39
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #39
原因
Electron 在 Linux 上会把 SIGTERM 转成
Browser::Quit()(最小 Electron 程序可正常退出)。问题在before-quit处理器:没有运行中的脚本时core.dispose()只靠微任务就完成,而回调返回时 Node 会清空微任务,.finally(() => app.quit())于是在外层Quit()写回结果之前重入。内层把is_quitting_设为 true 并关闭窗口,外层随后用「被阻止」的结果把它覆盖回 false;窗口关完后 Electron 只发window-all-closed,「关闭到托盘」模式下什么也不做,托盘已销毁,进程挂住。托盘「退出」不受影响(外面有 JS 栈,微任务要等它结束)。修改
app.quit()推迟到下一轮事件循环(setImmediate)。quit.spec.ts新增 SIGTERM 用例(Windows 跳过):空闲时正常退出(退出码 0);有运行中的脚本时停止整棵进程树。验证
quit.spec.ts3 个用例通过,约 1 秒退出;去掉修复后空闲用例超时失败。pnpm check通过;pnpm e2e中project-actions.spec.ts悬停卡片偶发失败一次(与本改动无关),单独重跑通过。