Skip to content

fix(main): force hard exit on app close to prevent zombie processes#4

Open
hennring wants to merge 1 commit into
riskcapital:mainfrom
hennring:main
Open

fix(main): force hard exit on app close to prevent zombie processes#4
hennring wants to merge 1 commit into
riskcapital:mainfrom
hennring:main

Conversation

@hennring

@hennring hennring commented Jun 9, 2026

Copy link
Copy Markdown

Problem

When closing the application window, the Renderer process terminates, but the remaining Electron/Chromium background tasks (Main, GPU, and Network processes) stay alive in the system's Task Manager.

Because of the app's single-instance lock implementation, these lingering "zombie" processes silently block users from reopening the application unless they manually kill the tasks via Task Manager. Furthermore, this resource lock causes file-permission errors (EPERM) during local build routines (npm run build:desktop).

The root cause is that hardware-heavy operations (like Spout/NDI) or active plugin child processes occasionally block Electron's graceful app.quit() lifecycle from successfully completing the event loop.

Solution

This PR refactors the cleanupAndQuit() function in the main process to ensure a guaranteed, unblockable application shutdown:

  1. Replaced app.quit() with app.exit(0): Once the cleanup logic has run, this forces all 3 active Chromium/Node tasks to exit immediately, bypassing Electron's easily obstructed graceful closing routine.
  2. Robust Exception Handling: Wrapped the NDI and plugin iteration blocks inside isolated try/catch statements. If a native addon throws an unhandled error or if plugins is undefined/null, the sequence will safely continue instead of crashing halfway through.
  3. Forced Plugin Destruction: Changed the plugin termination signal to SIGKILL to forcefully drop any active hardware or file handles.
  4. Streamlined Execution: Removed the deferred setTimeout block to maintain a clean, synchronous, and predictable linear execution flow.

Linked Issues

Fixes #3

Testing Checklist

  • Verified that the app UI closes successfully.
  • Confirmed via Task Manager that all 3 background processes (Main, GPU, Network) disappear instantly upon closing.
  • Verified that the application can be reopened immediately after closing.
  • Ran npm run build:desktop without encountering EPERM file-locking issues.

- Replaced graceful  with definitive  to ensure all 3 Chromium/Node background tasks terminate instantly.
- Removed  deferred exit logic in favor of a reliable linear execution flow.
- Added robust try/catch safety wrappers around NDI and plugin cleanup blocks to prevent unhandled exceptions from halting the exit sequence.
- Forced native plugin termination using .

Closes riskcapital#3

Signed-off-by: Henning Kĺoß <henningkloss@gmail.com>
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.

bug: App processes remain active after closing, blocking subsequent launches (on Windows)

1 participant