fix(processes): fix multiple clawx processes running concurently (#589)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Haze <hazeone@users.noreply.github.com> Co-authored-by: paisley <8197966+su8su@users.noreply.github.com> Co-authored-by: Felix <24791380+vcfgv@users.noreply.github.com>
This commit is contained in:
@@ -242,6 +242,7 @@ export class GatewayManager extends EventEmitter {
|
||||
await this.connect(port, externalToken);
|
||||
},
|
||||
onConnectedToExistingGateway: () => {
|
||||
|
||||
// If the existing gateway is actually our own spawned UtilityProcess
|
||||
// (e.g. after a self-restart code=1012), keep ownership so that
|
||||
// stop() can still terminate the process during a restart() cycle.
|
||||
@@ -250,6 +251,7 @@ export class GatewayManager extends EventEmitter {
|
||||
this.ownsProcess = false;
|
||||
this.setStatus({ pid: undefined });
|
||||
}
|
||||
|
||||
this.startHealthCheck();
|
||||
},
|
||||
waitForPortFree: async (port) => {
|
||||
@@ -356,6 +358,25 @@ export class GatewayManager extends EventEmitter {
|
||||
this.setStatus({ state: 'stopped', error: undefined, pid: undefined, connectedAt: undefined, uptime: undefined });
|
||||
}
|
||||
|
||||
/**
|
||||
* Best-effort emergency cleanup for app-quit timeout paths.
|
||||
* Only terminates a process this manager still owns.
|
||||
*/
|
||||
async forceTerminateOwnedProcessForQuit(): Promise<boolean> {
|
||||
if (!this.process || !this.ownsProcess) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const child = this.process;
|
||||
await terminateOwnedGatewayProcess(child);
|
||||
if (this.process === child) {
|
||||
this.process = null;
|
||||
}
|
||||
this.ownsProcess = false;
|
||||
this.setStatus({ pid: undefined });
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart Gateway process
|
||||
*/
|
||||
@@ -724,6 +745,7 @@ export class GatewayManager extends EventEmitter {
|
||||
|
||||
this.process = child;
|
||||
this.ownsProcess = true;
|
||||
logger.debug(`Gateway manager now owns process pid=${child.pid ?? 'unknown'}`);
|
||||
this.lastSpawnSummary = lastSpawnSummary;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user