azure-pipelines-agent: [BUG]: PowerShell task idles before generating script

What happened?

This is reported at https://developercommunity.visualstudio.com/t/PowerShell-task-idles-before-generating-/10636846, but got the suggestion to report here as well.


We’ve got several self hosted Azure DevOps Agent that runs on one of our servers.

We’ve seen an issue that escalated in the last month or so, I believe that it correlates with updating all Agents to latest release (v3.236.1) and at the same time we started to run on PowerShell 7 (with pwsh: true).

After server is started, our pipelines runs fast for several days, or maybe a week or so. Then we start to see performance problems, where a lot of tasks in the pipeline takes a lot longer to complete.

It seems as it is the PowerShell tasks (PowerShell@2) that takes longer and longer to start. When checking the logs we can see that the PowerShell task header is written to the log, then it idles before the text “Generating script” is being logged. Looking at old logs I can see that it used to take about 3 or 4s before “Generating script” is being printed.

2024-01-17T14:34:18.3486490Z ##[section]Starting: Create Build Container
2024-01-17T14:34:18.3652184Z ==============================================================================
2024-01-17T14:34:18.3652483Z Task : PowerShell
2024-01-17T14:34:18.3652629Z Description : Run a PowerShell script on Linux, macOS, or Windows
2024-01-17T14:34:18.3652823Z Version : 2.232.0
2024-01-17T14:34:18.3652970Z Author : Microsoft Corporation
2024-01-17T14:34:18.3653124Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2024-01-17T14:34:18.3653358Z ==============================================================================
2024-01-17T14:34:22.2085506Z Generating script.
2024-01-17T14:34:22.2418319Z ========================== Starting Command Output ===========================
2024-01-17T14:34:22.2628841Z ##[command]“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command “. ‘C:\Agent_AS015_scheduled_03_work_temp\ddcc7e46-c1ed-477b-badb-77d665f4bf1c.ps1’”

But when the server slows down lately this time increases and increases and increases until some colleague yells about it. Yesterday there was about 10 minutes between those two steps.

2024-04-10T13:22:50.2800169Z ##[section]Starting: Create Build Container
2024-04-10T13:22:50.2922041Z ==============================================================================
2024-04-10T13:22:50.2922184Z Task : PowerShell
2024-04-10T13:22:50.2922253Z Description : Run a PowerShell script on Linux, macOS, or Windows
2024-04-10T13:22:50.2922369Z Version : 2.237.5
2024-04-10T13:22:50.2922600Z Author : Microsoft Corporation
2024-04-10T13:22:50.2922694Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2024-04-10T13:22:50.2922805Z ==============================================================================
2024-04-10T13:32:35.6715441Z Generating script.
2024-04-10T13:32:35.7043642Z ========================== Starting Command Output ===========================
2024-04-10T13:32:35.7294220Z ##[command]“C:\Program Files\PowerShell\7\pwsh.exe” -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command “. ‘C:\Agent_AS015_01_work_temp\3243b6c1-4d9e-4855-b9eb-389a1dae31d0.ps1’”

If I restart the server, all is fine for some days, then this starts again.

When monitoring the server, I can see that the pipeline agents create a LOT (50 to 100 or so) of WMIC processes, which seems to cause high CPU load oon WmiPrvSE.exe… Is this expected behavior? They all just seems to check the available memory on the host. image

Yesterday, just before restarting the server, I saw above list of WMIC processes and they just seemed to live on. Today, I still see a lot of WMIC processes being started and we get a CPU spike in WmiPrvSE, but after a few seconds (3 to 4) they are terminated, and CPU goes down.

We’ve got 12 agents running on the same machine, with 32 cores and 128GB of RAM, but since they are divided into two different AgentPools there are most often no more than 6 agents running at the same time.

I believe I found the code that is starting the WMIC processes:

https://github.com/microsoft/azure-pipelines-agent/blob/b34a9c376bf689d70092981eaa40d3e19327b11a/src/Agent.Worker/ResourceMetricsManager.cs#L255

But why it is creating that many processes puzzles me… There is a loop in RunMemoryUtilizationMonitor() that should wait 5s between each check, but as it seems - this cannot work as intended, or am I mistaken?

Versions

Agent version: 3.236.1 Windows Version: Windows Server 2022, v21H2 (OS Build 20348.2402)

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

No response

Relevant log output

See under "What happened" above.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 22 (5 by maintainers)

Most upvoted comments

Hi @jwikman We are working on this, you can follow the progress on developer community portal - https://developercommunity.visualstudio.com/t/PowerShell-task-idles-before-generating-/10636846

Hi @ismayilov-ismayil I’ve uploaded some logs to this problem reported on DevCommunity, but they are not public. Can you access them as a MS representative somehow, or can I send you the logs in a non-public way?

I was running a very simple “Hello World” pipeline at the same time that we were experiencing this issue, with System Diagnostics enabled.