Skip to content

Commit 330b290

Browse files
committed
fix: reset daemon state after request timeout
1 parent c2c9bf0 commit 330b290

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/daemon-client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ async function sendRequest(info: DaemonInfo, req: DaemonRequest): Promise<Daemon
248248
const timeout = setTimeout(() => {
249249
socket.destroy();
250250
const cleanup = cleanupTimedOutIosRunnerBuilds();
251+
resetDaemonAfterTimeout(info);
251252
emitDiagnostic({
252253
level: 'error',
253254
phase: 'daemon_request_timeout',
@@ -257,6 +258,7 @@ async function sendRequest(info: DaemonInfo, req: DaemonRequest): Promise<Daemon
257258
command: req.command,
258259
timedOutRunnerPidsTerminated: cleanup.terminated,
259260
timedOutRunnerCleanupError: cleanup.error,
261+
daemonPidReset: info.pid,
260262
},
261263
});
262264
reject(
@@ -331,6 +333,17 @@ function cleanupTimedOutIosRunnerBuilds(): { terminated: number; error?: string
331333
}
332334
}
333335

336+
function resetDaemonAfterTimeout(info: DaemonInfo): void {
337+
void stopProcessForTakeover(info.pid, {
338+
termTimeoutMs: DAEMON_TAKEOVER_TERM_TIMEOUT_MS,
339+
killTimeoutMs: DAEMON_TAKEOVER_KILL_TIMEOUT_MS,
340+
expectedStartTime: info.processStartTime,
341+
}).finally(() => {
342+
removeDaemonInfo();
343+
removeDaemonLock();
344+
});
345+
}
346+
334347
export function resolveDaemonRequestTimeoutMs(raw: string | undefined = process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS): number {
335348
if (!raw) return 90000;
336349
const parsed = Number(raw);

0 commit comments

Comments
 (0)