Skip to content

Azure Function Powershell. Failed to debug locally with: "Internal Error - System.Management.Automation.PSInvalidOperationException: The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently." #2776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HoLengZai opened this issue Apr 21, 2021 · 1 comment

Comments

@HoLengZai
Copy link

Hello,

I got an issue with debugging my Azure Function (PowerShell language). I don't know if I'm on the correct GitHub project between all the extensions (PowerShell, Azure Function, Azure Function Core Tools, ...) so I pick "vscode-azurefunctions". (Please let me know if I need to post to other GitHub project. Thanks)

It doesn't stop (all the time) to my breakpoint and I have to kill my PowerShell Integration Terminal to run the debug again.
I don't have any issue when I run my code on a separate PowerShell project (=without Azure Function runtime)

Here the error message from the Debug Console Window after asking to display Error:
Get-Error

Internal Error - System.Management.Automation.PSInvalidOperationException: The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
   at System.Management.Automation.RemotePipeline.DoConcurrentCheck(Boolean syncCall)
   at System.Management.Automation.RemoteRunspace.DoConcurrentCheckAndAddToRunningPipelines(RemotePipeline pipeline, Boolean syncCall)
   at System.Management.Automation.RemotePipeline.InitPowerShell(Boolean syncCall, Boolean invokeAndDisconnect)
   at System.Management.Automation.RemotePipeline.Invoke(IEnumerable input)
   at System.Management.Automation.RemoteSessionStateProxy.get_LanguageMode()
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteScriptStringAsync(String scriptString, StringBuilder errorMessages, Boolean writeInputToHost, Boolean writeOutputToHost, Boolean addToHistory) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 1018
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteScriptStringAsync(String scriptString, Boolean writeInputToHost, Boolean writeOutputToHost) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 979
   at Microsoft.PowerShell.EditorServices.Handlers.DebugEvaluateHandler.Handle(EvaluateRequestArguments request, CancellationToken cancellationToken) in D:\a\1\s\src\PowerShellEditorServices\Services\DebugAdapter\Handlers\DebugEvaluateHandler.cs:line 44
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|5_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token, ILogger logger)
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)
   at OmniSharp.Extensions.JsonRpc.InputHandler.<>c__DisplayClass38_0.<<RouteRequest>b__5>d.MoveNext()

I try to create a new Azure Function without adding new code. I got the same issue with the debugger, so I cannot debug anything properly as I got strange behaviour of my Azure Function like it doesn't break at the breakpoint all the time or I do not get any Output from my Write-Host or Write-Verbose.
I have to kill the terminal as Ctrl-C or Detach command doesn't work or do not respond.
Then I got plenty of "PowerShell Editor Services" output window (as you can see on the gif below)

Here my config:
Windows 10 v20H2 build 19042.928
Core Tools Version: 3.0.3442 (64-bit)
Function Runtime Version: 3.0.15417.0
PowerShell version installed: 7.1.3
When I run the Azure Function, it turns to 7.0 (which is correct based on what I read)

Here my local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME_VERSION": "~7",
    "FUNCTIONS_WORKER_RUNTIME": "powershell"
  }
}

Here my host.json: (Even without extensionBundle, or/and applicationInsights or/and logging or/and managedDependency block, I always got an issue for debugging)

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "debugOnly",
    "logLevel": {
      "Function": "Debug"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  },
  "managedDependency": {
    "enabled": true
  }
}

Here my function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "Request",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "Response"
    }
  ]
}

Here my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to PowerShell Functions",
      "type": "PowerShell",
      "request": "attach",
      "customPipeName": "AzureFunctionsPSWorker",
      "runspaceId": 1,
      "preLaunchTask": "func: host start"
    }
  ]
}

Here my tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "func",
      "command": "host start",
      "problemMatcher": "$func-powershell-watch",
      "isBackground": true
    }
  ]
}

As mentioned, It's a "fresh" new Azure Function to confirm that it's not related to my project source code application.

After killing

1> Debugging Runspace: PowerShellManager1
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.


Command or script completed.
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.

Command or script completed.
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.

Entering debugged runspace on local machine MY_COMPUTER

Command or script completed.
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.

Leaving debugged runspace on local machine MY_COMPUTER

Here how it looks like as I really don't understand which "thing" make it unusable to test my Azure Function locally

azfunction_debug_bug

@ejizba
Copy link
Contributor

ejizba commented May 3, 2021

It appears PowerShell/PowerShellEditorServices#1295 may be the root cause. Will track in #2734

@ejizba ejizba closed this as completed May 3, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants