Skip to content

Fix app not quitting when no child processes are running (macOS) - #215

Open
JulianGlueck wants to merge 1 commit into
NativePHP:mainfrom
JulianGlueck:fix/quit-without-child-processes
Open

JulianGlueck wants to merge 1 commit into
NativePHP:mainfrom
JulianGlueck:fix/quit-without-child-processes

Conversation

@JulianGlueck

Copy link
Copy Markdown

Problem

Since the before-quit handler waits for child processes to exit, an app without any child processes (e.g. 'queue_workers' => []) no longer quits on macOS. The windows close, but the app stays in the Dock. Clicking the Dock icon does nothing, because the PHP server has already been killed.

Cause

Without running processes, the wait loop never awaits. So the final app.quit() runs synchronously, while the outer before-quit handler is still running:

  1. The inner app.quit() passes before-quit (this.quitting is already true). Electron marks the quit as accepted and starts closing the windows.
  2. Control returns to the outer quit. Its event was preventDefault()ed, so Electron resets its quitting state.
  3. When the last window closes, Electron doesn't treat it as a quit anymore and emits window-all-closed.

On Windows and Linux, the same happens, but the window-all-closed handler calls app.quit() again, which then goes through. So the symptom only shows on macOS, where the app deliberately stays open without windows.

With at least one child process (e.g. a queue worker), the loop awaits once. app.quit() then runs after the handler has returned, which is why this went unnoticed.

Fix

Defer the final app.quit() to the next tick with setImmediate(). Then it always runs after the outer quit has finished, whether or not any processes are running.

Steps to reproduce

  1. Set 'queue_workers' => [] in config/nativephp.php (and don't start any other child processes).
  2. Run the app on macOS.
  3. Press Cmd+Q: the app stays in the Dock and can't be reopened.

With this change, the app quits as expected.

@simonhamp

Copy link
Copy Markdown
Member

Good find! Thanks

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.

2 participants