Skip to content

fix: handle SIGTERM for graceful shutdown on system shutdown/logout#335

Merged
icebear0828 merged 1 commit intomasterfrom
fix/sigterm-graceful-shutdown
Apr 8, 2026
Merged

fix: handle SIGTERM for graceful shutdown on system shutdown/logout#335
icebear0828 merged 1 commit intomasterfrom
fix/sigterm-graceful-shutdown

Conversation

@icebear0828
Copy link
Copy Markdown
Owner

Follow-up to #324.

Problem

before-quit intercepts all quit events on macOS (event.preventDefault()), including OS-initiated ones (system shutdown, logout). macOS sends SIGTERM, Electron converts it to app.quit()before-quit, but allowProcessExit is still false → event is blocked. macOS waits ~5s then SIGKILL.

Fix

process.on("SIGTERM", () => {
  if (!isQuitting) quitApplication();
});

quitApplication() sets allowProcessExit = true synchronously. Since before-quit is dispatched as a Chromium task (asynchronous), the flag is set before before-quit fires — server gets a graceful cleanup window before exit.

Test plan

  • System shutdown / logout → app exits gracefully (no SIGKILL delay)
  • Window close / Cmd+Q still hides to tray (existing behavior unchanged)
  • Tray "Quit" still does graceful shutdown
  • npm test passes

Without this, before-quit intercepts OS-initiated termination (system
shutdown, logout), causing macOS to wait then SIGKILL the process.

process.on('SIGTERM') calls quitApplication() which sets allowProcessExit
synchronously before before-quit fires, enabling graceful server cleanup.
@icebear0828 icebear0828 merged commit 3c30f2f into master Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant