Skip to content

stopProcess throws uncaught exception when process has already exited #89

@igorgudelj

Description

@igorgudelj

When stopAllProcesses() is called during before-quit, killSync() throws if a child process has already exited. This surfaces as an Electron "JavaScript error in the main process" dialog on Windows.

Uncaught Exception:
Error: Command failed: taskkill /pid 76672 /T /F
ERROR: The process "76672" not found.

    at killSync (node_modules/kill-sync/dist/cjs/kill.js:22:42)
    at stopProcess (electron-plugin/dist/server/api/childProcess.js)
    at stopAllProcesses (electron-plugin/dist/server/api/childProcess.js)

The function already guards against a missing alias (if (proc === undefined) return), but doesn't handle the case where the process object exists in state while the OS process has already terminated.

This can happen when:

  • The PHP process crashes or exits on its own before app quit
  • stopAllProcesses() is called more than once during shutdown (e.g. before-quit fires multiple times)
  • autoUpdater.quitAndInstall() triggers a quit while a quit is already in progress

Steps to reproduce

  1. Start a NativePHP app on Windows
  2. Trigger a scenario where the PHP child process exits before stopAllProcesses() runs during before-quit
  3. Close the app

Expected: App closes cleanly.
Actual: Error dialog: "A JavaScript error occurred in the main process"

Suggested fix

Wrap the kill calls in stopProcess with a try-catch — a dead process is the desired outcome, not an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions