summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2026-03-23 16:44:23 +0800
committerGitHub <[email protected]>2026-03-23 08:44:23 +0000
commit4c27e7fc6499dee385e718d523c4f0612bd8a063 (patch)
tree2a48fd9ae771c083653a9d68a1d239df42d91aab
parent0f5626d2e46f9f8abfe616a33a4fd4f4d989e396 (diff)
downloadopencode-4c27e7fc6499dee385e718d523c4f0612bd8a063.tar.gz
opencode-4c27e7fc6499dee385e718d523c4f0612bd8a063.zip
electron: more robust sidecar kill handling (#18742)
-rw-r--r--packages/desktop-electron/src/main/cli.ts3
-rw-r--r--packages/desktop-electron/src/main/index.ts18
2 files changed, 20 insertions, 1 deletions
diff --git a/packages/desktop-electron/src/main/cli.ts b/packages/desktop-electron/src/main/cli.ts
index fba301f36..f2d918bd2 100644
--- a/packages/desktop-electron/src/main/cli.ts
+++ b/packages/desktop-electron/src/main/cli.ts
@@ -35,6 +35,7 @@ export type CommandEvent =
export type SqliteMigrationProgress = { type: "InProgress"; value: number } | { type: "Done" }
export type CommandChild = {
+ pid: number | undefined
kill: () => void
}
@@ -191,7 +192,7 @@ export function spawnCommand(args: string, extraEnv: Record<string, string>) {
treeKill(child.pid)
}
- return { events, child: { kill }, exit }
+ return { events, child: { pid: child.pid, kill }, exit }
}
function handleSqliteProgress(events: EventEmitter, line: string) {
diff --git a/packages/desktop-electron/src/main/index.ts b/packages/desktop-electron/src/main/index.ts
index 484e4feb2..032343204 100644
--- a/packages/desktop-electron/src/main/index.ts
+++ b/packages/desktop-electron/src/main/index.ts
@@ -81,6 +81,17 @@ function setupApp() {
killSidecar()
})
+ app.on("will-quit", () => {
+ killSidecar()
+ })
+
+ for (const signal of ["SIGINT", "SIGTERM"] as const) {
+ process.on(signal, () => {
+ killSidecar()
+ app.exit(0)
+ })
+ }
+
void app.whenReady().then(async () => {
// migrate()
app.setAsDefaultProtocolClient("opencode")
@@ -234,8 +245,15 @@ registerIpcHandlers({
function killSidecar() {
if (!sidecar) return
+ const pid = sidecar.pid
sidecar.kill()
sidecar = null
+ // tree-kill is async; also send process group signal as immediate fallback
+ if (pid && process.platform !== "win32") {
+ try {
+ process.kill(-pid, "SIGTERM")
+ } catch {}
+ }
}
function ensureLoopbackNoProxy() {