fix: fix worker node event emitter memory leak
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 26 Nov 2023 10:48:15 +0000 (11:48 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 26 Nov 2023 10:48:15 +0000 (11:48 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
benchmarks/benchmarks-utils.js
src/pools/abstract-pool.ts

index 24762e5f0033f807de9901e216ed73216dd4bd18..a9795487bcf20a72e1559d8cc5c79afbf42595ad 100644 (file)
@@ -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
 
index 678b41d7634e56254c3cfb660738aea2cf8ee20d..b7826a0c27ae06a75921df2df531128685c57afb 100644 (file)
@@ -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
index 43af4f7c6868820fdfeb748d611aff2a2b35ddfa..d51970ef216f3c2e60c2fb07c8a6c145058df7b7 100644 (file)
@@ -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()