From 2cb4ff45b1171d4978e7bfca62a04bb359042a68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 24 Aug 2023 23:27:18 +0200 Subject: [PATCH] fix: ensure task stealing respects the tasks queueing semantic MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index a6ffcbbb..062df077 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1253,18 +1253,14 @@ export abstract class AbstractPool< ...(sourceWorkerNode.popTask() as Task), workerId: destinationWorkerNode.info.id as number } - // Enqueue task for continuous task stealing - this.enqueueTask(destinationWorkerNodeKey, task) - // Avoid starvation if ( - this.tasksQueueSize(destinationWorkerNodeKey) > 0 && + this.tasksQueueSize(destinationWorkerNodeKey) === 0 && destinationWorkerNode.usage.tasks.executing < (this.opts.tasksQueueOptions?.concurrency as number) ) { - this.executeTask( - destinationWorkerNodeKey, - this.dequeueTask(destinationWorkerNodeKey) as Task - ) + this.executeTask(destinationWorkerNodeKey, task) + } else { + this.enqueueTask(destinationWorkerNodeKey, task) } break } -- 2.34.1