azure-pipelines-tasks: BashV3 task incorrectly sends SIGTERM to child process instead of SIGINT
Required Information
Type: Bug Task Name: BashV3
Environment
Server: Azure Pipelines Agent: Hosted
Issue Description
BashV3 contains code to listen for SIGINT from the agent and forward the signal to the child process (via the ToolRunner.killChildProcess() method). This logic was initially introduced in https://github.com/microsoft/azure-pipelines-tasks/pull/13573.
The implementation does not work as expected, for two reasons:
-
Because of https://github.com/microsoft/azure-pipelines-task-lib/issues/858 the POSIX signals get mixed up; the agent sends
SIGINTto the task, but the task ends up sendingSIGTERMto the child process. -
The task listens only for
SIGINTbut it should also listen forSIGTERMbecause as stated here the agent apparently sends both, at different times to indicate different levels of urgency.
A more correct implementation would be:
- Add a parameter in upstream
ToolRunner.killChildProcess()to allow specifying the signal to send - Listen for
SIGINTand callbash.killChildProcess("SIGINT"); - Listen for
SIGTERMand callbash.killChildProcess("SIGTERM");
Small changes are necessary in both libraries to address this, so I will create issues and PRs in both repos and update both with links to cross-reference.
Task logs
Here’s a simple repro pipeline:
pool:
vmImage: ubuntu-latest
trigger: none
jobs:
- job: signals
displayName: Test POSIX signals
# Have the job cancel after 1 minute:
timeoutInMinutes: 1
steps:
- checkout: none
- bash: |
trap "echo 'SIGHUP'" SIGHUP
trap "echo 'SIGINT'" SIGINT
trap "echo 'SIGQUIT'" SIGQUIT
trap "echo 'SIGTERM'" SIGTERM
trap "echo 'EXIT'" EXIT
while true; do sleep 1; echo .; done
displayName: Wait for signals
Running it will show the following:
As show in the screenshot, the script task receives SIGTERM and nothing else.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 15 (3 by maintainers)
@ivanduplenskikh Awesome - good things come to those who wait! 😉
@DaRosenberg, the PR with signal handling in BashV3 and CmdLineV2 tasks has been merged to the master. Now, we’re waiting for the next tasks’ release.