question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PowerShell debugging session crashes when debugging ends

See original GitHub issue

System Details

System Details Output

### VSCode version: 
1.52.1 ea3859d4ba2f3e577a159bc91e3074c5d85c0523 x64

### VSCode extensions:
ms-vscode.powershell@2020.6.0

### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.1
PSEdition                      Core
GitCommitId                    7.1.1
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

(I’ve disabled all extensions except for the PowerShell extension).

Possibly also of note is that I have PowerShell installed as a .NET Global Tool using .NET SDK v5.0.102

Issue Description

After a few debugging sessions, the session will appear to end successfully, but then the Integrated Terminal will crash. Sometimes this occurs after only two or three runs, but sometimes it can be after seven, eight or even more successful runs. It doesn’t seem to matter what the script does. Here’s a screen capture of running a script that simply calls Write-Host.

ps

Expected Behaviour

PowerShell doesn’t crash.

Actual Behaviour

The PowerShell session will crash with the error:

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.
Unhandled exception. System.AggregateException: One or more errors occurred. (One or more errors occurred. (Safe handle has been closed.
Object name: 'SafeHandle'.))
 ---> System.AggregateException: One or more errors occurred. (Safe handle has been closed.
Object name: 'SafeHandle'.)
 ---> System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
   at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
   at Interop.Kernel32.CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped)
   at System.IO.Pipes.PipeCompletionSource`1.Cancel()
   at System.IO.Pipes.PipeCompletionSource`1.<>c.<RegisterForCancellation>b__14_0(Object thisRef)
   at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
   --- End of inner exception stack trace ---
   at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
   at Nerdbank.Streams.PipeExtensions.<>c.<UsePipeReader>b__18_0(Exception ex, Object state)
   at System.IO.Pipelines.PipeCompletionCallbacks.Execute(PipeCompletionCallback callback, List`1& exceptions)
   --- End of inner exception stack trace ---
   at System.IO.Pipelines.PipeCompletionCallbacks.Execute()
   at System.IO.Pipelines.Pipe.<>c.<.cctor>b__90_2(Object state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

The same error is reported in Event Viewer:

Application: dotnet.exe
CoreCLR Version: 5.0.220.61120
.NET Version: 5.0.2
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AggregateException: One or more errors occurred. (One or more errors occurred. (Safe handle has been closed.
Object name: 'SafeHandle'.))
<... snip ...>

Attached Logs

logs.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
SydneyhSmithcommented, Feb 23, 2021

Thanks for the update @reduckted we do not have any additional logging instrumented right now for you to turn on, however as we tackle this issue we may have future builds of the extension for you to test out, thanks for your patience!

1reaction
SydneyhSmithcommented, Feb 9, 2021

Thanks @reduckted for providing the detailed issue report including the GIF, and logs/stack trace, it is really appreciated! It looks as though something is causing the named pipe to close at the transport layer…this one will be difficult to debug…in the meantime you may want to try the PowerShell Preview extension as the issue may be resolved in that version…thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

PowerShell session has terminated upon loading a script with ...
Place a breakpoint on the ps1 file and press F5 or Run > Start Debugging (and you'll notice that its running under Powershell...
Read more >
Crash when entering debug mode for the second time in a ...
To work around this issue, you can do one of the following: Close the tool window(s) that are docked as tabbed documents while...
Read more >
Attach to running processes with the Visual Studio debugger
Select the computer or device you want, and then click Select. Note. The Connection type setting persists between debugging sessions. The ...
Read more >
Debugging 102: My script only crashes when I run it, never in ...
But usually, crash bugs are the easiest to fix. Just load the offending application or script in a debugger, run it, repeat the...
Read more >
Program corrections for the IAR Embedded Workbench
Enabling the Function Profiler under a debug session can cause a crash. ... as a back-end driver option, instead of as an option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found