fix: some more edges cases in the worker choice strategy retries code
[poolifier.git] / src / pools / selection-strategies / round-robin-worker-choice-strategy.ts
index 41bc4085ebd5a1399975e48e873fc0612c6a611c..b6d222f59995c523770120d515571bdb8c129b54 100644 (file)
@@ -54,6 +54,8 @@ export class RoundRobinWorkerChoiceStrategy<
     this.roundRobinNextWorkerNodeKey()
     if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) {
       this.nextWorkerNodeKey = undefined
+      this.previousWorkerNodeKey =
+        chosenWorkerNodeKey ?? this.previousWorkerNodeKey
     }
     return chosenWorkerNodeKey
   }
@@ -74,7 +76,7 @@ export class RoundRobinWorkerChoiceStrategy<
     this.nextWorkerNodeKey =
       this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
         ? 0
-        : (this.nextWorkerNodeKey ?? 0) + 1
+        : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
     return this.nextWorkerNodeKey
   }
 }