fix: destroy worker only on check alive checks
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 7 Apr 2023 18:00:27 +0000 (20:00 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 7 Apr 2023 18:00:27 +0000 (20:00 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/pools/cluster/dynamic.ts
src/pools/thread/dynamic.ts

index 2e033fc1614c0a778c85569d98cb8e014f010bcc..0d583217f9edb3ac079894bd5f8cbc05d0fb7e9c 100644 (file)
@@ -302,7 +302,8 @@ export abstract class AbstractPool<
       this.registerWorkerMessageListener(createdWorker, message => {
         if (
           isKillBehavior(KillBehaviors.HARD, message.kill) ||
-          this.getWorkerTasksUsage(createdWorker)?.running === 0
+          (message.kill != null &&
+            this.getWorkerTasksUsage(createdWorker)?.running === 0)
         ) {
           // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
           void this.destroyWorker(createdWorker)
index 6171ce4e8a4b51991294677b680e9373d8e64313..b84a80ce2b31b7fc807bceae6b29e1a7eb2af5bd 100644 (file)
@@ -27,7 +27,7 @@ export class DynamicClusterPool<
    */
   public constructor (
     min: number,
-    private readonly max: number,
+    public readonly max: number,
     filePath: string,
     opts: ClusterPoolOptions = {}
   ) {
index 62ddba9fc4792148a47f69c51c8c6f7a01b3adb0..d8cc3a7427ca0f843c2c9f839747b3a663b9b95c 100644 (file)
@@ -28,7 +28,7 @@ export class DynamicThreadPool<
    */
   public constructor (
     min: number,
-    private readonly max: number,
+    public readonly max: number,
     filePath: string,
     opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
   ) {