Skip to content

electron: more robust sidecar kill handling#18742

Merged
Brendonovich merged 1 commit intodevfrom
brendan/electron-sidecar-kill
Mar 23, 2026
Merged

electron: more robust sidecar kill handling#18742
Brendonovich merged 1 commit intodevfrom
brendan/electron-sidecar-kill

Conversation

@Brendonovich
Copy link
Copy Markdown
Collaborator

Adds some extra handlers to ensure that the CLI sidecar is killed

@Brendonovich Brendonovich enabled auto-merge (squash) March 23, 2026 08:36
Copy link
Copy Markdown

@atharvau atharvau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: electron: more robust sidecar kill handling

⚠️ CRITICAL ISSUES

1. Race Condition in Signal Handlers

The app.exit(0) call immediately terminates the process without waiting for killSidecar() to complete. Since sidecar killing might be asynchronous (tree-kill), this creates a race condition where the main process exits before the sidecar is properly terminated.

Fix: Remove app.exit(0) or make the handler async and await cleanup.

2. Process Group Kill Without Validation

Sending signals to process groups (-pid) can kill unintended processes if the PID was reused. The silent catch masks potential issues.

Fix: Add PID validation and better error handling:

if (pid && process.platform !== "win32" && pid === sidecar?.pid) {
  try {
    process.kill(-pid, "SIGTERM")
  } catch (error) {
    console.warn(`Failed to kill process group ${pid}:`, error)
  }
}

🔶 SUGGESTIONS

Multiple Signal Handler Registration

If this code runs multiple times, it will register duplicate handlers. Consider using process.once() instead of process.on().

Enhanced killSidecar

Consider adding a small delay before the process group kill to let tree-kill complete:

// Give tree-kill time to work, then fallback
await new Promise(resolve => setTimeout(resolve, 100))

The approach is solid overall, but the race condition with app.exit(0) should be addressed.

@Brendonovich Brendonovich merged commit 4c27e7f into dev Mar 23, 2026
11 checks passed
@Brendonovich Brendonovich deleted the brendan/electron-sidecar-kill branch March 23, 2026 08:44
burn2delete pushed a commit to burn2delete/symbolic that referenced this pull request Mar 24, 2026
Andres77872 pushed a commit to Andres77872/opencode that referenced this pull request Mar 26, 2026
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