From 9f99eb9b411c296f8e69e758fd2296902be4fca4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 26 Nov 2023 11:48:15 +0100 Subject: [PATCH] fix: fix worker node event emitter memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 1 + benchmarks/benchmarks-utils.js | 4 ++-- src/pools/abstract-pool.ts | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24762e5f..a9795487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove all pool events listener at pool destroying. - Remove all worker node events listener at worker node destroying. +- Fix worker node event emitter listeners handling memory leak at pool options runtime change. ## [3.0.8] - 2023-11-25 diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 678b41d7..b7826a0c 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -81,9 +81,9 @@ const runPoolifierPoolBenchmark = async ( poolSize, { taskExecutions, workerData } ) => { - const pool = buildPoolifierPool(workerType, poolType, poolSize) - const suite = new Benchmark.Suite(name) return await new Promise((resolve, reject) => { + const pool = buildPoolifierPool(workerType, poolType, poolSize) + const suite = new Benchmark.Suite(name) try { for (const workerChoiceStrategy of Object.values( WorkerChoiceStrategies diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 43af4f7c..d51970ef 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -594,11 +594,13 @@ export abstract class AbstractPool< this.buildTasksQueueOptions(tasksQueueOptions) this.setTasksQueueSize(this.opts.tasksQueueOptions.size as number) if (this.opts.tasksQueueOptions.taskStealing === true) { + this.unsetTaskStealing() this.setTaskStealing() } else { this.unsetTaskStealing() } if (this.opts.tasksQueueOptions.tasksStealingOnBackPressure === true) { + this.unsetTasksStealingOnBackPressure() this.setTasksStealingOnBackPressure() } else { this.unsetTasksStealingOnBackPressure() -- 2.34.1