diff --git a/src/cliproxy/auth/oauth-process.ts b/src/cliproxy/auth/oauth-process.ts index 9f6fb39d..344e156b 100644 --- a/src/cliproxy/auth/oauth-process.ts +++ b/src/cliproxy/auth/oauth-process.ts @@ -6,6 +6,19 @@ */ import { spawn, ChildProcess } from 'child_process'; + +/** + * Kill process with SIGTERM, escalating to SIGKILL if it doesn't exit + */ +function killWithEscalation(proc: ChildProcess, gracePeriodMs = 3000): void { + proc.kill('SIGTERM'); + const timer = setTimeout(() => { + if (proc.exitCode === null) { + proc.kill('SIGKILL'); + } + }, gracePeriodMs); + proc.once('exit', () => clearTimeout(timer)); +} import { ok, fail, info, warn } from '../../utils/ui'; import { tryKiroImport } from './kiro-import'; import { CLIProxyProvider } from '../types'; @@ -333,8 +346,8 @@ export function executeOAuthProcess(options: OAuthProcessOptions): Promise { if (stdinKeepalive) clearInterval(stdinKeepalive); - if (authProcess && !authProcess.killed) { - authProcess.kill('SIGTERM'); + if (authProcess && authProcess.exitCode === null) { + killWithEscalation(authProcess); } }; process.on('SIGINT', cleanup); @@ -425,7 +438,8 @@ export function executeOAuthProcess(options: OAuthProcessOptions): Promise { // H7: Clear stdin keepalive interval if (stdinKeepalive) clearInterval(stdinKeepalive); @@ -435,9 +449,9 @@ export function executeOAuthProcess(options: OAuthProcessOptions): Promise