Skip to content

Commit 1cbe313

Browse files
committed
git commit -m "fix: guard against double worker failure handling #29451"
1 parent 180ede2 commit 1cbe313

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

apps/api/v2/src/modules/slots/slots-2024-04-15/services/slots-worker.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class SlotsWorkerService_2024_04_15 implements OnModuleDestroy {
3232
private readonly logger = new Logger("SlotsWorkerService_2024_04_15");
3333
private readonly workerPool: Worker[] = [];
3434
private readonly maxWorkers: number;
35+
private handledWorkers = new Set<number>();
3536
private readonly taskQueue: Array<{
3637
resolve: (value: TimeSlots) => void;
3738
reject: (reason: Error) => void;
@@ -93,8 +94,13 @@ export class SlotsWorkerService_2024_04_15 implements OnModuleDestroy {
9394
*/
9495
private handleWorkerFailure(failedWorker: Worker): void {
9596
// Remove the failed worker from both pools
96-
this.logger.error(`Handling Worker ${failedWorker.threadId} failure`);
97-
this.workerPool.splice(this.workerPool.indexOf(failedWorker), 1);
97+
if (this.handledWorkers.has(failedWorker.threadId)) return;
98+
this.handledWorkers.add(failedWorker.threadId)
99+
const workerIndex = this.workerPool.indexOf(failedWorker);
100+
if (workerIndex !== -1) {
101+
this.workerPool.splice(workerIndex, 1);
102+
}
103+
98104
this.availableWorkers = this.availableWorkers.filter((w) => w !== failedWorker);
99105

100106
try {

0 commit comments

Comments
 (0)