Skip to content

Commit 2574461

Browse files
authored
Merge pull request #3190 from artilleryio/hassy-art-1859-fargate-workers-not-handling-sigterm-correctly
fix: handle SIGTERM correctly on Fargate
2 parents cf78d4a + 199c0d6 commit 2574461

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/artillery/lib/cmds/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ RunCommand.runCommandImplementation = async function (flags, argv, args) {
337337
var finalReport = {};
338338
var shuttingDown = false;
339339
process.on('SIGINT', async () => {
340-
gracefulShutdown({ earlyStop: true });
340+
gracefulShutdown({ earlyStop: true, exitCode: 130 });
341341
});
342342
process.on('SIGTERM', async () => {
343-
gracefulShutdown({ earlyStop: true });
343+
gracefulShutdown({ earlyStop: true, exitCode: 143 });
344344
});
345345

346346
async function gracefulShutdown(opts = { exitCode: 0 }) {

packages/artillery/lib/platform/aws-ecs/worker/loadgen-worker

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,19 @@ cleanup () {
418418
if [[ $CLI_RUNNING = "yes" ]] ; then
419419
printf "Interrupted with %s, stopping\n" "$sig"
420420
EXIT_CODE=$ERR_INTERRUPTED
421-
kill -TERM $CLI_PID # TODO: Check handling in A9 CLI
422-
wait $CLI_PID
423-
CLI_STATUS=$(cat exitCode) # TODO: Could be 0, but is not a successful run
421+
kill -TERM $CLI_PID
422+
set +e
423+
timeout 20 tail --pid $CLI_PID -f /dev/null
424+
if [[ $? -eq 124 ]] ; then
425+
# timeout exits with 124 if the process it's waiting on is still running
426+
# i.e. if tail is still running it means the Artillery CLI did not exit:
427+
kill -KILL $CLI_PID
428+
CLI_STATUS=143 # SIGTERM (128 + 15)
429+
else
430+
# Preserve the exit code of the CLI
431+
CLI_STATUS=$(cat exitCode)
432+
fi
433+
set -e
424434
CLI_RUNNING="no"
425435
fi
426436

0 commit comments

Comments
 (0)