mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 10:16:49 +00:00
refactor(utils): extract killWithEscalation to shared process-utils
- Move killWithEscalation to src/utils/process-utils.ts (DRY) - Fix handleCancel to use exitCode === null and killWithEscalation - Fix import ordering in both oauth-process.ts and headless-executor.ts
This commit is contained in:
@@ -6,20 +6,8 @@
|
||||
*/
|
||||
|
||||
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 { killWithEscalation } from '../../utils/process-utils';
|
||||
import { tryKiroImport } from './kiro-import';
|
||||
import { CLIProxyProvider } from '../types';
|
||||
import { AccountInfo } from '../account-manager';
|
||||
@@ -371,9 +359,9 @@ export function executeOAuthProcess(options: OAuthProcessOptions): Promise<Accou
|
||||
|
||||
// Listen for external cancel signal
|
||||
const handleCancel = (cancelledSessionId: string) => {
|
||||
if (cancelledSessionId === state.sessionId && authProcess && !authProcess.killed) {
|
||||
if (cancelledSessionId === state.sessionId && authProcess && authProcess.exitCode === null) {
|
||||
log('Session cancelled externally');
|
||||
authProcess.kill('SIGTERM');
|
||||
killWithEscalation(authProcess);
|
||||
}
|
||||
};
|
||||
authSessionEvents.on('session:cancelled', handleCancel);
|
||||
|
||||
@@ -5,21 +5,9 @@
|
||||
* Spawns claude with -p flag for single-turn execution
|
||||
*/
|
||||
|
||||
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 { spawn } from 'child_process';
|
||||
import * as path from 'path';
|
||||
import { killWithEscalation } from '../utils/process-utils';
|
||||
import * as fs from 'fs';
|
||||
import { SessionManager } from './session-manager';
|
||||
import { SettingsParser } from './settings-parser';
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Process management utilities
|
||||
*/
|
||||
|
||||
import { ChildProcess } from 'child_process';
|
||||
|
||||
/**
|
||||
* Kill process with SIGTERM, escalating to SIGKILL if it doesn't exit.
|
||||
* Uses exitCode === null (not proc.killed) to check if process is still running,
|
||||
* since proc.killed only indicates a signal was sent, not that the process exited.
|
||||
*/
|
||||
export 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));
|
||||
}
|
||||
Reference in New Issue
Block a user