Skip to content

Comments

fix: properly cleanup Windows process tree on Obsidian exit#33

Closed
Gerkinfeltser wants to merge 1 commit intomtymek:mainfrom
Gerkinfeltser:fix/windows-process-cleanup-v2
Closed

fix: properly cleanup Windows process tree on Obsidian exit#33
Gerkinfeltser wants to merge 1 commit intomtymek:mainfrom
Gerkinfeltser:fix/windows-process-cleanup-v2

Conversation

@Gerkinfeltser
Copy link
Contributor

On Windows, when Obsidian closes with the OpenCode panel open, the server process (node.exe) becomes orphaned because:

  1. shell: true spawns cmd.exe → node.exe
  2. The PID captured is cmd.exe, not the actual node.exe
  3. Killing cmd.exe leaves node.exe running

Solution

Store the PID separately in main.ts and use PowerShell to reliably find and kill child processes.

Changes

  • WindowsProcess.stop(): Use PowerShell to find and kill child processes first
  • ServerManager: Added getPid() method
  • main.ts: Store serverPid separately for cleanup during window close
  • main.ts: Added killPidSync() with PowerShell child lookup (Windows)
  • main.ts: Added beforeunload handler for reliable cleanup on window close
  • main.ts: Updated onunload() to use sync cleanup with stored PID

Testing

Tested on Windows 11:

  • Server stops when closing Obsidian window
  • No orphaned node.exe processes after exit"

On Windows, when Obsidian closes with the OpenCode panel open, the server
process (node.exe) becomes orphaned because:
1. shell: true spawns cmd.exe -> node.exe
2. The PID captured is cmd.exe, not the actual node.exe
3. Killing cmd.exe leaves node.exe running

Changes:
- WindowsProcess.stop(): Use PowerShell to find and kill child processes first
- ServerManager: Added getPid() method
- main.ts: Store serverPid separately for cleanup during window close
- main.ts: Added killPidSync() with PowerShell child lookup (Windows)
- main.ts: Added beforeunload handler for reliable cleanup on window close
- main.ts: Updated onunload() to use sync cleanup with stored PID

This ensures the actual node.exe process is killed when Obsidian closes.
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