Skip to content

Commit

Permalink
Merge pull request #3190 from artilleryio/hassy-art-1859-fargate-work…
Browse files Browse the repository at this point in the history
…ers-not-handling-sigterm-correctly

fix: handle SIGTERM correctly on Fargate
  • Loading branch information
hassy authored Jun 10, 2024
2 parents cf78d4a + 199c0d6 commit 2574461
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/artillery/lib/cmds/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ RunCommand.runCommandImplementation = async function (flags, argv, args) {
var finalReport = {};
var shuttingDown = false;
process.on('SIGINT', async () => {
gracefulShutdown({ earlyStop: true });
gracefulShutdown({ earlyStop: true, exitCode: 130 });
});
process.on('SIGTERM', async () => {
gracefulShutdown({ earlyStop: true });
gracefulShutdown({ earlyStop: true, exitCode: 143 });
});

async function gracefulShutdown(opts = { exitCode: 0 }) {
Expand Down
16 changes: 13 additions & 3 deletions packages/artillery/lib/platform/aws-ecs/worker/loadgen-worker
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,19 @@ cleanup () {
if [[ $CLI_RUNNING = "yes" ]] ; then
printf "Interrupted with %s, stopping\n" "$sig"
EXIT_CODE=$ERR_INTERRUPTED
kill -TERM $CLI_PID # TODO: Check handling in A9 CLI
wait $CLI_PID
CLI_STATUS=$(cat exitCode) # TODO: Could be 0, but is not a successful run
kill -TERM $CLI_PID
set +e
timeout 20 tail --pid $CLI_PID -f /dev/null
if [[ $? -eq 124 ]] ; then
# timeout exits with 124 if the process it's waiting on is still running
# i.e. if tail is still running it means the Artillery CLI did not exit:
kill -KILL $CLI_PID
CLI_STATUS=143 # SIGTERM (128 + 15)
else
# Preserve the exit code of the CLI
CLI_STATUS=$(cat exitCode)
fi
set -e
CLI_RUNNING="no"
fi

Expand Down

0 comments on commit 2574461

Please sign in to comment.