Add-AzureRmVhd sporadically fails with error "The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently"
Cmdlet(s)
Add-AzureRmVhd
Module Version
Compute module 1.2.3.4 - azure stack version
Description
We are trying to upload the image to a storage blob. As a part of putting the image into the blob, we use Add-AzureRmVhd (https://github.com/Azure/AzureStack-Tools/blob/e73d52686d9db0f63b3560019d47cc65c77d147b/ComputeAdmin/AzureStack.ComputeAdmin.psm1#L183) This cmdlet sporadically fails with "The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently"
The issue is also discussed here. https://social.msdn.microsoft.com/Forums/en-US/2e825e81-d00e-42ef-bec7-4a92a5565a33/can-run-addazurevhd?forum=windowsazuremanagement
I have checked the latest code with stack-dev branch code for this particular cmdlet. There are no changes addressing this issue
@hyonholee, may I know if you had a chance to look at this issue? If not, could you let me know when we expect an update?
I'm encountering the same issue. @hyonholee Can you maybe add a -force option so the current running pipeline can terminated and let the Add-AzureRmVhd continue?
I'm encountering the same issue on Windows Server 1907 on Azure
Same issue is still hapening for us. We have now created a do/while loop to get around this issue.
ping @hyonholee
@praries880 Are you hitting this issue against Azure or AZURESTACK? Whats your module version of Compute
@bganapa againt azure.
I am getting the same issue. Any update ?
@gsingla294 SAME PROBLEM. Any fixes?
Same problem with the new Add-AzVhd ! :-1:
Thanks for reporting the issue. We will investigate it. Thanks.
Tested the Add-AzVhd cmdlet with Az.Compute (4.2.1) and I wasn't able to reproduce the bug.

Any stack trace anyone experiencing this can provide would help to pinpoint the cause of this issue. In Windows PowerShell 5.1 this can be obtained with $error[0] | fl * -force and possibly $error[0].Exception | fl * -force. In PowerShell 7, you can use Get-Error.
From https://github.com/PowerShell/PowerShell/issues/13497, the issue was occurring here:
https://github.com/Azure/azure-powershell/blob/1bcbe7b1f7a3323ac98f7754ba03eeb6b45e79f2/src/Compute/Compute/Models/PSSyncOutputEvents.cs#L92-L101
This was caused by trying to reuse a runspace already in use to run another PowerShell invocation. The correct solution for this depends on the requirements of the scenario, but looking at the code in that class it seems to all be UI facing, meaning an easy first iteration on a fix would be to do away with PowerShell creation and instead calling the Host UI directly:
- From within a PSCmdlet, you can access the current
PSHost - From there you can get the UI class,
PSHostUserInterface - That in turn has methods for writing to the UI that can be used concurrency without throwing (although doing so may look very odd to the user)
We've been running into this issue regularly. We added the exception logging code that @rjmholt suggested above, which came back with this
ErrorRecord : The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
Message : The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
Data : {}
InnerException :
TargetSite : Void DoConcurrentCheck(Boolean, System.Object, Boolean)
StackTrace : at System.Management.Automation.Runspaces.PipelineBase.DoConcurrentCheck(Boolean syncCall, Object
syncObject, Boolean isInLock)
at System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(Pi
pelineBase pipeline, Boolean syncCall)
at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumerable input, Boolean
syncCall)
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean
performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace
rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1
input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input,
PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at Microsoft.Azure.Commands.Compute.Models.PSSyncOutputEvents.LogProgressComplete(Int32
activityId, String activity)
at Microsoft.Azure.Commands.Compute.Models.PSSyncOutputEvents.ProgressUploadComplete(TimeSpan
elapsed)
at Microsoft.WindowsAzure.Commands.Sync.ProgressTracker.Dispose(Boolean disposing)
at Microsoft.WindowsAzure.Commands.Sync.ProgressTracker.Dispose()
at Microsoft.WindowsAzure.Commands.Sync.Upload.BlobSynchronizer.Synchronize()
at Microsoft.Azure.Commands.Compute.Models.VhdUploaderModel.Upload(UploadParameters
uploadParameters)
at Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HelpLink :
Source : System.Management.Automation
HResult : -2146233079
In our case we're trying to run this as part of a CI system, and since this seems to be relating to the progress bar (which isn't even visible anywhere) we're going to see if we can set $ProgressPreference = "SilentlyContinue" to work around this for now.
@MSLaguana Also consider adding few retries in a loop.
For what it's worth, after we turned off progress updates we haven't seen this bite us again, so that seems like a workable mitigation until the underlying issue is fixed.
I had the same error, is there any update on this?
:bell: Routing this issue to @act-observability-squad.