fix: fix race condition at task response handling during pool destroy
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 14 Aug 2024 18:07:43 +0000 (20:07 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 14 Aug 2024 18:22:17 +0000 (20:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index 77ce43c3702f643f58ea42bd405aa7c86185e522..8aab6695ed2a241aaaec11cada85b3567eb312c2 100644 (file)
@@ -2146,7 +2146,6 @@ export abstract class AbstractPool<
       this.afterTaskExecutionHook(workerNodeKey, message)
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       this.promiseResponseMap.delete(taskId!)
-      workerNode.emit('taskFinished', taskId)
       if (this.opts.enableTasksQueue === true && !this.destroying) {
         const workerNodeTasksUsage = workerNode.usage.tasks
         if (
@@ -2164,6 +2163,7 @@ export abstract class AbstractPool<
           })
         }
       }
+      workerNode.emit('taskFinished', taskId)
     }
   }