Skip to content

Commit 18d1daa

Browse files
committed
fix(webapp): guard the OTLP worker pool against double-reap and late messages
A crashing worker fires both error and exit, so reap() ran twice (double respawn and double backoff increment). reap() now returns early once the worker has been removed. The message handler also ignores late messages from an already-reaped worker, which otherwise pushed a dead worker back into the idle set.
1 parent 5c62877 commit 18d1daa

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

apps/webapp/app/v3/otlpWorkerPool.server.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class OtlpWorkerPool {
5454
});
5555

5656
worker.on("message", (msg: { id: number; ok: boolean; result?: any; error?: string }) => {
57+
if (this.workers.indexOf(worker) === -1) return; // late message from an already-reaped worker
5758
this.consecutiveFailures = 0;
5859
this.busyByWorker.delete(worker);
5960
const task = this.tasks.get(msg.id);
@@ -84,6 +85,13 @@ export class OtlpWorkerPool {
8485
// On crash/timeout: fail the worker's in-flight task (if still pending), drop the worker, and
8586
// respawn with exponential backoff so a persistently failing worker can't tight-loop.
8687
private reap(worker: Worker, error: Error) {
88+
const wi = this.workers.indexOf(worker);
89+
if (wi === -1) return; // already reaped (error + exit can both fire for one crash)
90+
this.workers.splice(wi, 1);
91+
92+
const ii = this.idle.indexOf(worker);
93+
if (ii !== -1) this.idle.splice(ii, 1);
94+
8795
const inFlightId = this.busyByWorker.get(worker);
8896
this.busyByWorker.delete(worker);
8997
if (inFlightId !== undefined) {
@@ -94,10 +102,7 @@ export class OtlpWorkerPool {
94102
task.reject(error);
95103
}
96104
}
97-
const wi = this.workers.indexOf(worker);
98-
if (wi !== -1) this.workers.splice(wi, 1);
99-
const ii = this.idle.indexOf(worker);
100-
if (ii !== -1) this.idle.splice(ii, 1);
105+
101106
void worker.terminate().catch(() => {});
102107
this.scheduleRespawn();
103108
}

0 commit comments

Comments
 (0)