From 83cfac37fcca2039612ce5b743be7e406527cef1 Mon Sep 17 00:00:00 2001 From: hveldstra Date: Wed, 11 Dec 2024 13:16:18 +0000 Subject: [PATCH] fix: avoid launching extra tasks on ECS Fargate Currently if we run into a capacity issue on Fargate, we wait and retry again, but without taking into account that some of the tasks in a given batch of 10 did actually start. This leads to two issues: 1. More tasks than the value of `--count` end up getting launched 2. The check for whether all workers started up fails because the number of "ready" files does not match the count, and the test run eventually fails with a "sync timeout" error --- .../platform/aws-ecs/legacy/run-cluster.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js b/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js index cbacb6425c..ccbdc48ae6 100644 --- a/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js +++ b/packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js @@ -1713,6 +1713,19 @@ async function ecsRunTask(context) { try { const runData = await ecs.runTask(params).promise(); + + const launchedTasksCount = runData.tasks?.length || 0; + tasksRemaining -= launchedTasksCount; + + if (launchedTasksCount > 0) { + const newTaskArns = runData.tasks.map((task) => task.taskArn); + context.taskArns = context.taskArns.concat(newTaskArns); + artillery.globalEvents.emit('metadata', { + platformMetadata: { taskArns: newTaskArns } + }); + debug(`Launched ${launchedTasksCount} tasks`); + } + if (runData.failures.length > 0) { artillery.log('Some workers failed to start'); const uniqueReasons = [ @@ -1723,19 +1736,6 @@ async function ecsRunTask(context) { await sleep(10 * 1000); throw new Error('Not enough ECS capacity'); } - - if (runData.tasks?.length > 0) { - const newTaskArns = runData.tasks.map((task) => task.taskArn); - context.taskArns = context.taskArns.concat(newTaskArns); - artillery.globalEvents.emit('metadata', { - platformMetadata: { taskArns: newTaskArns } - }); - debug(`Launched ${launchCount} tasks`); - tasksRemaining -= launchCount; - await sleep(250); - } else { - retries++; - } } catch (runErr) { if (runErr.code === 'ThrottlingException') { artillery.log('ThrottlingException returned from ECS, retrying');