From 3e1a27030242ffef06bcf888e39271e822893f41 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Tue, 16 Dec 2025 21:02:38 +0900 Subject: [PATCH] fix(lsp): cleanup orphan LSP servers on process exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement cross-platform process cleanup handlers for LSP servers. Added registerProcessCleanup() method to LSPServerManager that: - Kills all spawned LSP server processes on process.exit - Handles SIGINT (Ctrl+C) - all platforms - Handles SIGTERM (kill signal) - Unix/macOS/Linux - Handles SIGBREAK (Ctrl+Break) - Windows specific This prevents LSP servers from becoming orphan processes when opencode terminates unexpectedly. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/tools/lsp/client.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/tools/lsp/client.ts b/src/tools/lsp/client.ts index 5d879bc..1906dd6 100644 --- a/src/tools/lsp/client.ts +++ b/src/tools/lsp/client.ts @@ -21,6 +21,45 @@ class LSPServerManager { private constructor() { this.startCleanupTimer() + this.registerProcessCleanup() + } + + private registerProcessCleanup(): void { + const cleanup = () => { + for (const [, managed] of this.clients) { + try { + managed.client.stop() + } catch {} + } + this.clients.clear() + if (this.cleanupInterval) { + clearInterval(this.cleanupInterval) + this.cleanupInterval = null + } + } + + // Works on all platforms + process.on("exit", cleanup) + + // Ctrl+C - works on all platforms + process.on("SIGINT", () => { + cleanup() + process.exit(0) + }) + + // Kill signal - Unix/macOS + process.on("SIGTERM", () => { + cleanup() + process.exit(0) + }) + + // Ctrl+Break - Windows specific + if (process.platform === "win32") { + process.on("SIGBREAK", () => { + cleanup() + process.exit(0) + }) + } } static getInstance(): LSPServerManager {