fix: fix possible null exception at handling task execution response
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 17 Dec 2023 21:16:09 +0000 (22:16 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 17 Dec 2023 21:16:09 +0000 (22:16 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
src/pools/abstract-pool.ts

index 8e2d5edb5ca8bac6438e57a6a050c000214afba6..cb7d4bffe11d8cbdd67c1e6e2362223ee05d07d3 100644 (file)
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Fixed
+
+- Fix possible null exception at handling task execution response.
+
 ## [3.1.2] - 2023-12-17
 
 ### Fixed
index beacddf3852a1174d21ec8a69180d1521cebd42b..635b8af459363dc022671f089492f155b3470695 100644 (file)
@@ -1740,6 +1740,7 @@ export abstract class AbstractPool<
     const promiseResponse = this.promiseResponseMap.get(taskId as string)
     if (promiseResponse != null) {
       const { resolve, reject, workerNodeKey, asyncResource } = promiseResponse
+      const workerNode = this.workerNodes[workerNodeKey]
       if (workerError != null) {
         this.emitter?.emit(PoolEvents.taskError, workerError)
         asyncResource != null
@@ -1758,9 +1759,9 @@ export abstract class AbstractPool<
       this.afterTaskExecutionHook(workerNodeKey, message)
       this.workerChoiceStrategyContext.update(workerNodeKey)
       this.promiseResponseMap.delete(taskId as string)
-      this.workerNodes[workerNodeKey].emit('taskFinished', taskId)
+      workerNode.emit('taskFinished', taskId)
       if (this.opts.enableTasksQueue === true) {
-        const workerNodeTasksUsage = this.workerNodes[workerNodeKey].usage.tasks
+        const workerNodeTasksUsage = workerNode.usage.tasks
         if (
           this.tasksQueueSize(workerNodeKey) > 0 &&
           workerNodeTasksUsage.executing <
@@ -1776,7 +1777,7 @@ export abstract class AbstractPool<
           this.tasksQueueSize(workerNodeKey) === 0 &&
           workerNodeTasksUsage.sequentiallyStolen === 0
         ) {
-          this.workerNodes[workerNodeKey].emit('idleWorkerNode', {
+          workerNode.emit('idleWorkerNode', {
             workerId: workerId as number,
             workerNodeKey
           })