From: Jérôme Benoit Date: Sun, 17 Dec 2023 21:16:09 +0000 (+0100) Subject: fix: fix possible null exception at handling task execution response X-Git-Tag: v3.1.3~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9b358e72dbd061a7b94708d7d3c64e9dbbefaab4;p=poolifier.git fix: fix possible null exception at handling task execution response Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e2d5edb..cb7d4bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index beacddf3..635b8af4 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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 })