Skip to content

[BUG]: Temporary script generated from azure pipeline script step is not delivering termination signal to the child processes #5501

@vnemanja995

Description

@vnemanja995

What happened?

I created the script with following content:

#!/bin/bash

set -e -o pipefail

podman run --init --rm ubuntu:24.04 bash -c "
for i in {1..500}; do
echo \"Loop iteration \$i\"
sleep 1
done
echo 'All done!'" &
POD_PID=$!
# Register exit handlers for signals
trap 'echo signal int received!;kill -TERM $POD_PID' SIGINT
trap 'echo signal term received!;kill -TERM $POD_PID' SIGTERM
wait $POD_PID

I am calling it in azure pipeline like this:
- script: ./script.sh "some arg"

This is how azure is invoking it
./script.sh "some arg"

If the script is called without any arg:
- script: ./script.sh

Azure is invoking it like this:
exec ./script.sh

When invoking script with arguments, the trap handlers I defined in script.sh(to catch SIGINT and SIGTERM) never executed when pipeline is canceled.
Trap handlers are only executed if the script is called without any arguments.

Versions

Azure DevOps Version 4.269.0 / Ubuntu 24.04

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

No response

Version controll system

Azure repos / Git

Relevant log output

# Debug log: pipeline is executed with arguments and canceled manually.

Script contents:
./script.sh "some dummy args..."
========================== Starting Command Output ===========================
##[debug]which 'bash'
##[debug]found: '/usr/bin/bash'
##[debug]which '/usr/bin/bash'
##[debug]found: '/usr/bin/bash'
##[debug]/usr/bin/bash arg: --noprofile
##[debug]/usr/bin/bash arg: --norc
##[debug]/usr/bin/bash arg: /home/agent/agent/_work/_temp/0afa59f4-80fb-4e00-bfe9-287e459680b2.sh
##[debug]exec tool: /usr/bin/bash
##[debug]arguments:
##[debug]   --noprofile
##[debug]   --norc
##[debug]   /home/agent/agent/_work/_temp/0afa59f4-80fb-4e00-bfe9-287e459680b2.sh
/usr/bin/bash --noprofile --norc /home/agent/agent/_work/_temp/0afa59f4-80fb-4e00-bfe9-287e459680b2.sh
Loop iteration 1
Loop iteration 2
Loop iteration 3
Loop iteration 4
Loop iteration 5
##[debug]Agent environment resources - Disk: / Available 233235.95 MB out of 252863.98 MB, Memory: Used 1054.00 MB out of 24081.00 MB, CPU: Usage 2.00%
Loop iteration 6
Loop iteration 7
Loop iteration 8
Loop iteration 9
Loop iteration 10
Loop iteration 11
##[debug]Agent environment resources - Disk: / Available 233235.91 MB out of 252863.98 MB, Memory: Used 1054.00 MB out of 24081.00 MB, CPU: Usage 0.00%
Loop iteration 12
Loop iteration 13
Loop iteration 14
Loop iteration 15
##[debug]Re-evaluate condition on job cancellation for step: 'Debug external script'.
##[error]The Operation will be canceled. The next steps may not contain expected logs.
##[debug][killChildProcess] Signal SIGINT received
Loop iteration 16
Loop iteration 17
Loop iteration 18
Loop iteration 19
Loop iteration 20
Loop iteration 21
Loop iteration 22
Loop iteration 23
##[debug][killChildProcess] Signal SIGTERM received
Loop iteration 24
Loop iteration 25
##[error]The operation was canceled.
##[debug]System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.CancellationToken.ThrowIfCancellationRequested()
   at Microsoft.VisualStudio.Services.Agent.Util.ProcessInvoker.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue`1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, Boolean continueAfterCancelProcessTreeKillAttempt, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/src/Agent.Sdk/ProcessInvoker.cs:line 394
   at Microsoft.VisualStudio.Services.Agent.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue`1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, Boolean continueAfterCancelProcessTreeKillAttempt, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/src/Microsoft.VisualStudio.Services.Agent/ProcessInvoker.cs:line 329
   at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.DefaultStepHost.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Boolean inheritConsoleHandler, Boolean continueAfterCancelProcessTreeKillAttempt, TimeSpan sigintTimeout, TimeSpan sigtermTimeout, Boolean useGracefulShutdown, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/src/Agent.Worker/Handlers/StepHost.cs:line 86
   at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.NodeHandler.RunAsync() in /mnt/vss/_work/1/s/src/Agent.Worker/Handlers/NodeHandler.cs:line 306
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsyncInternal() in /mnt/vss/_work/1/s/src/Agent.Worker/TaskRunner.cs:line 477
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync() in /mnt/vss/_work/1/s/src/Agent.Worker/TaskRunner.cs:line 81
   at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken) in /mnt/vss/_work/1/s/src/Agent.Worker/StepsRunner.cs:line 369

# Debug log: pipeline is executed without arguments and canceled manually.

Script contents:
exec ./script.sh
========================== Starting Command Output ===========================
##[debug]which 'bash'
##[debug]found: '/usr/bin/bash'
##[debug]which '/usr/bin/bash'
##[debug]found: '/usr/bin/bash'
##[debug]/usr/bin/bash arg: --noprofile
##[debug]/usr/bin/bash arg: --norc
##[debug]/usr/bin/bash arg: /home/agent/agent/_work/_temp/ab78b164-301e-43bf-96f7-54008e405432.sh
##[debug]exec tool: /usr/bin/bash
##[debug]arguments:
##[debug]   --noprofile
##[debug]   --norc
##[debug]   /home/agent/agent/_work/_temp/ab78b164-301e-43bf-96f7-54008e405432.sh
/usr/bin/bash --noprofile --norc /home/agent/agent/_work/_temp/ab78b164-301e-43bf-96f7-54008e405432.sh
Loop iteration 1
Loop iteration 2
Loop iteration 3
Loop iteration 4
##[debug]Agent environment resources - Disk: / Available 233211.70 MB out of 252863.98 MB, Memory: Used 1077.00 MB out of 24081.00 MB, CPU: Usage 1.67%
Loop iteration 5
Loop iteration 6
Loop iteration 7
Loop iteration 8
Loop iteration 9
##[debug]Agent environment resources - Disk: / Available 233211.65 MB out of 252863.98 MB, Memory: Used 1078.00 MB out of 24081.00 MB, CPU: Usage 1.67%
Loop iteration 10
Loop iteration 11
Loop iteration 12
Loop iteration 13
Loop iteration 14
##[debug]Agent environment resources - Disk: / Available 233211.61 MB out of 252863.98 MB, Memory: Used 1080.00 MB out of 24081.00 MB, CPU: Usage 0.00%
Loop iteration 15
Loop iteration 16
Loop iteration 17
Loop iteration 18
Loop iteration 19
##[debug]Agent environment resources - Disk: / Available 233211.57 MB out of 252863.98 MB, Memory: Used 1082.00 MB out of 24081.00 MB, CPU: Usage 0.00%
Loop iteration 20
##[debug]Re-evaluate condition on job cancellation for step: 'Debug external script'.
##[error]The Operation will be canceled. The next steps may not contain expected logs.
##[debug][killChildProcess] Signal SIGINT received
signal int received!
##[debug]Process exited with code 130 and signal null for tool '/usr/bin/bash'
##[debug]STDIO streams have closed and received exit code 130 and signal null for tool '/usr/bin/bash'
##[error]Bash exited with code '130'.
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;correlationId=5d585274-bc0c-4464-858b-faa552eca3f1;]Bash exited with code '130'.
##[debug]task result: Failed
##[debug]Processed: ##vso[task.complete result=Failed;done=true;]
##[error]The operation was canceled.
##[debug]System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at Microsoft.VisualStudio.Services.Agent.Util.ProcessInvoker.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue`1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, Boolean continueAfterCancelProcessTreeKillAttempt, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/src/Agent.Sdk/ProcessInvoker.cs:line 394
   at Microsoft.VisualStudio.Services.Agent.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue`1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, Boolean continueAfterCancelProcessTreeKillAttempt, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/src/Microsoft.VisualStudio.Services.Agent/ProcessInvoker.cs:line 329
   at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.DefaultStepHost.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Boolean inheritConsoleHandler, Boolean continueAfterCancelProcessTreeKillAttempt, TimeSpan sigintTimeout, TimeSpan sigtermTimeout, Boolean useGracefulShutdown, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/src/Agent.Worker/Handlers/StepHost.cs:line 86
   at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.NodeHandler.RunAsync() in /mnt/vss/_work/1/s/src/Agent.Worker/Handlers/NodeHandler.cs:line 306
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsyncInternal() in /mnt/vss/_work/1/s/src/Agent.Worker/TaskRunner.cs:line 477
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync() in /mnt/vss/_work/1/s/src/Agent.Worker/TaskRunner.cs:line 81
   at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken) in /mnt/vss/_work/1/s/src/Agent.Worker/StepsRunner.cs:line 369

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions