]> Piment Noir Git Repositories - poolifier.git/commitdiff
refactor: ensure safer access to worker node status
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 8 Jul 2025 15:04:29 +0000 (17:04 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 8 Jul 2025 15:04:29 +0000 (17:04 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index f69921b5c451cc3ec7755733664eca459fe22c69..2d8255f92c03b4ff47c4fdb3fabd203dfdbb157d 100644 (file)
@@ -2082,11 +2082,19 @@ export abstract class AbstractPool<
 
   private isWorkerNodeBackPressured (workerNodeKey: number): boolean {
     const workerNode = this.workerNodes[workerNodeKey]
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+    if (workerNode == null) {
+      return false
+    }
     return workerNode.info.ready && workerNode.info.backPressure
   }
 
   private isWorkerNodeBusy (workerNodeKey: number): boolean {
     const workerNode = this.workerNodes[workerNodeKey]
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+    if (workerNode == null) {
+      return false
+    }
     if (this.opts.enableTasksQueue === true) {
       return (
         workerNode.info.ready &&
@@ -2100,6 +2108,10 @@ export abstract class AbstractPool<
 
   private isWorkerNodeIdle (workerNodeKey: number): boolean {
     const workerNode = this.workerNodes[workerNodeKey]
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+    if (workerNode == null) {
+      return false
+    }
     if (this.opts.enableTasksQueue === true) {
       return (
         workerNode.info.ready &&
@@ -2112,6 +2124,10 @@ export abstract class AbstractPool<
 
   private isWorkerNodeStealing (workerNodeKey: number): boolean {
     const workerNode = this.workerNodes[workerNodeKey]
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+    if (workerNode == null) {
+      return false
+    }
     return (
       workerNode.info.ready &&
       (workerNode.info.continuousStealing ||