Skip to content

Commit

Permalink
Standardize and fix exit code handling
Browse files Browse the repository at this point in the history
- Propagate non-zero exit codes up through run.sh/run.cmd/runsvc.sh
- Ensure .cmd scripts use 2 for retries (as was done for .sh in actions#1708)

Fixes actions#2769
Supersedes actions#2719
  • Loading branch information
jenseng committed Jul 26, 2024
1 parent 1250684 commit 3f4c8bb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/Misc/layoutbin/RunnerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ var runService = function () {

if (!stopping) {
setTimeout(runService, 5000);
} else {
process.exitCode = code;
}
});
} catch (ex) {
Expand Down
12 changes: 6 additions & 6 deletions src/Misc/layoutroot/run-helper.cmd.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ if %ERRORLEVEL% EQU 0 (

if %ERRORLEVEL% EQU 1 (
echo "Runner listener exit with terminated error, stop the service, no retry needed."
exit /b 0
exit /b 1
)

if %ERRORLEVEL% EQU 2 (
echo "Runner listener exit with retryable error, re-launch runner in 5 seconds."
ping 127.0.0.1 -n 6 -w 1000 >NUL
exit /b 1
exit /b 2
)

if %ERRORLEVEL% EQU 3 (
Expand All @@ -32,7 +32,7 @@ if %ERRORLEVEL% EQU 3 (
)
ping 127.0.0.1 -n 2 -w 1000 >NUL
)
exit /b 1
exit /b 2
)

if %ERRORLEVEL% EQU 4 (
Expand All @@ -46,13 +46,13 @@ if %ERRORLEVEL% EQU 4 (
)
ping 127.0.0.1 -n 2 -w 1000 >NUL
)
exit /b 1
exit /b 2
)

if %ERRORLEVEL% EQU 5 (
echo "Runner listener exit with Session Conflict error, stop the service, no retry needed."
exit /b 0
exit /b 5
)

echo "Exiting after unknown error code: %ERRORLEVEL%"
exit /b 0
exit /b %ERRORLEVEL%
6 changes: 3 additions & 3 deletions src/Misc/layoutroot/run-helper.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [[ $returnCode == 0 ]]; then
exit 0
elif [[ $returnCode == 1 ]]; then
echo "Runner listener exit with terminated error, stop the service, no retry needed."
exit 0
exit 1
elif [[ $returnCode == 2 ]]; then
echo "Runner listener exit with retryable error, re-launch runner in 5 seconds."
"$DIR"/safe_sleep.sh 5
Expand Down Expand Up @@ -72,8 +72,8 @@ elif [[ $returnCode == 4 ]]; then
exit 2
elif [[ $returnCode == 5 ]]; then
echo "Runner listener exit with Session Conflict error, stop the service, no retry needed."
exit 0
exit 5
else
echo "Exiting with unknown error code: ${returnCode}"
exit 0
exit $returnCode
fi
4 changes: 2 additions & 2 deletions src/Misc/layoutroot/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ rem ****************************************************************************
copy "%~dp0run-helper.cmd.template" "%~dp0run-helper.cmd" /Y
call "%~dp0run-helper.cmd" %*

if %ERRORLEVEL% EQU 1 (
if %ERRORLEVEL% EQU 2 (
echo "Restarting runner..."
goto :launch_helper
) else (
echo "Exiting runner..."
exit /b 0
exit /b %ERRORLEVEL%
)
2 changes: 1 addition & 1 deletion src/Misc/layoutroot/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ run() {
echo "Restarting runner..."
else
echo "Exiting runner..."
exit 0
exit $returnCode
fi
done
}
Expand Down

0 comments on commit 3f4c8bb

Please sign in to comment.