Skip to content

Commit

Permalink
fix: avoid launching extra tasks on ECS Fargate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hassy committed Dec 11, 2024
1 parent 4a6a5aa commit 83cfac3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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');
Expand Down

0 comments on commit 83cfac3

Please sign in to comment.