fix(desktop): use tree-kill to ensure subprocesses are killed when closing ports#946
Conversation
…osing ports When killing a process listening on a port, only the main process was being signaled, leaving child processes (like dev server workers) running. This caused ports to remain in use after attempting to close them. - Add treeKillWithEscalation utility that sends SIGTERM, polls for exit, and escalates to SIGKILL after 2 seconds - Update port-manager.ts to use tree-kill for killPort - Update manager.ts kill/cleanup methods to use tree-kill for terminal sessions - Handle EPERM correctly (process exists but lacks permission) - Update tests to mock treeKillWithEscalation
📝 WalkthroughWalkthroughThe pull request introduces asynchronous process termination with a new tree-kill escalation mechanism. It creates a Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant treeKillWithEscalation
participant System as System (process.kill)
participant Monitor as Monitor (polling)
Caller->>treeKillWithEscalation: treeKillWithEscalation({ pid, signal: "SIGTERM" })
treeKillWithEscalation->>System: process.kill(pid, SIGTERM)
treeKillWithEscalation->>Monitor: Start polling for process aliveness
Monitor->>System: process.kill(pid, 0) - check aliveness
System-->>Monitor: Process exists
Monitor->>Monitor: Wait & retry (fixed interval)
Monitor->>System: process.kill(pid, 0) - escalation timeout reached
System-->>Monitor: Process still exists
treeKillWithEscalation->>System: process.kill(pid, SIGKILL)
Note over System: SIGKILL forces termination
Monitor->>System: process.kill(pid, 0) - verify termination
System-->>Monitor: ESRCH (process gone)
treeKillWithEscalation-->>Caller: { success: true }
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
process.kill(), leaving child processes (like dev server workers) runningtreeKillWithEscalationutility that usestree-killto kill the entire process tree, with SIGTERM → SIGKILL escalation after 2 secondsport-manager.ts,manager.tskill/cleanup methods to use tree-killTest plan
npm run dev), click "Close port" in the ports list, verify child processes are killedSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.