Skip to content

Powershell Intergrated console terminates when ending debug session #1441

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
msturtz2017 opened this issue Jul 18, 2018 · 12 comments
Closed
Labels

Comments

@msturtz2017
Copy link

msturtz2017 commented Jul 18, 2018

System Details

  • Operating system name and version: Windows 10 1803 (OS Build 17134.81)

  • VS Code version: 1.25.1

  • PowerShell extension version: 1.8.1

- Output from `$PSVersionTable`:
Name                           Value
----                           -----
PSVersion                      5.1.17134.81
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.81
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

$pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      8      1      0

code --list-extensions --show-versions
$PSVersionTable

Issue Description

I am experiencing a problem with...

PowerShell Intergated terminal terminates after debug session

Step to reproduce
Install PowerShell extension 1.8.1
Click reload to so the extension is available
In Visual Code Open folder that has valid PowerShell files
Open ps1 file and set some BreakPoints in the file
Start PowerShell debugging session using VS Code ( PowerShell Integrated Console )
Stop debug session

Expected results
The PowerShell Intergated terminal should continue running

Actual
PowerShell Intergated terminal has terminated would you like to restart it

Workaround
Downgrade to 1.7.0 Extension

@TylerLeonhardt
Copy link
Member

Thanks for the info! Can you also attach the logs here so we can get a better idea of what's going on?

@msturtz2017
Copy link
Author

I am working internally at Microsoft cannot attach the log

@TylerLeonhardt
Copy link
Member

In that case, can you email them to [email protected] ?

@rjmholt
Copy link
Contributor

rjmholt commented Aug 9, 2018

Hi @msturtz2017 did you get a chance to send through those logs?

@rjmholt
Copy link
Contributor

rjmholt commented Aug 17, 2018

Not yet able to reproduce this. Will try again on a Windows machine tomorrow

@JustinGrote
Copy link
Collaborator

@rjmholt This may be the same issue as the PSReadline I've been seeing. I usually see it when doing Interactive Session, and when I stop it happens immediately.

Here's my initial repro:
PowerShell/PowerShellEditorServices#672 (comment)

And the follow-on logs:

EditorServices.log


2018-08-07 16:11:11.959 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'OnDebuggerStop', line 2152:
    Received debugger resume action Stop

2018-08-07 16:11:11.960 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Event 'powerShell/executionStatusChanged'

2018-08-07 16:11:11.961 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'OnSessionStateChanged', line 1569:
    Session state changed --
    
        Old state: Aborting
        New state: Ready
        Result: Completed

2018-08-07 16:11:11.961 [ERROR] C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommand', line 698:
    Execution of the following command(s) completed with errors:
    
        $MySHDLDefinitions = Import-SHDLDefinitionsFromExcel -skipnational -skipmarket -skipregional -SiteDefinitionFilePath .\TEST-SeasonsHospiceSiteList.xlsx -Path .\SeasonsHospiceDistributionListDefinitions.xlsx -verbose -prefix "" -SimulatedUser @{UserPrincipalName='[email protected]';Company='Seasons Hospice and Palliative Care of Arizona, LLC';Title='Director-Business Operations'}
        Out-Default
    
    

2018-08-07 16:11:11.962 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Event 'powerShell/executionStatusChanged'

2018-08-07 16:11:11.965 [ERROR] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs: In method 'OnExecutionCompleted', line 127:
    Exception occurred while awaiting debug launch task.

System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<OnExecutionCompleted>d__22.MoveNext()

2018-08-07 16:11:11.965 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs: In method 'OnExecutionCompleted', line 132:
    Execution completed, terminating...

2018-08-07 16:11:11.966 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommand', line 628:
    Attempting to execute command(s):
    
        prompt
    

2018-08-07 16:11:11.966 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\Host\EditorServicesPSHostUserInterface.cs: In method 'ShowCommandPrompt', line 154:
    StartReadLoop called while read loop is already running

2018-08-07 16:11:11.966 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'OnSessionStateChanged', line 1569:
    Session state changed --
    
        Old state: Ready
        New state: Running
        Result: NotFinished

2018-08-07 16:11:11.966 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Event 'powerShell/executionStatusChanged'

2018-08-07 16:11:11.967 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Response 'disconnect' with id 84

2018-08-07 16:11:11.969 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Event 'continued'

2018-08-07 16:11:11.970 [NORMAL] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs: In method 'Stop', line 178:
    Debug adapter is shutting down...

2018-08-07 16:11:11.970 [NORMAL] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: In method 'OnDebugServiceClientConnect', line 312:
    Previous debug session ended, restarting debug service listener...

2018-08-07 16:11:11.970 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\Channel\NamedPipeServerListener.cs: In method 'Stop', line 94:
    Named pipe server shutting down...

2018-08-07 16:11:11.970 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\Channel\NamedPipeServerListener.cs: In method 'Stop', line 98:
    Named pipe server has been disposed.

2018-08-07 16:11:11.992 [VERBOSE] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: In method 'ListenForMessages', line 355:
    MessageReader attempted to read from a disposed stream, ending MessageDispatcher loop

2018-08-07 16:11:12.000 [ERROR] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: In method 'OnListenTaskCompleted', line 391:
    ProtocolEndpoint message loop terminated due to unhandled exception:
    
    System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot access a closed pipe.
       at System.IO.__Error.PipeNotOpen()
       at System.IO.Pipes.PipeStream.CheckWriteOperations()
       at System.IO.Pipes.PipeStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
       at System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
       at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
       at System.IO.Stream.BeginEndWriteAsync(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
       at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageWriter.<WriteMessage>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageWriter.<WriteEvent>d__9`2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<>c__DisplayClass27_1`2.<<SendEvent>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.PowerShell.EditorServices.Utility.ThreadSynchronizationContext.RunLoopOnCurrentThread()
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a closed pipe.
       at System.IO.__Error.PipeNotOpen()
       at System.IO.Pipes.PipeStream.CheckWriteOperations()
       at System.IO.Pipes.PipeStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
       at System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
       at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
       at System.IO.Stream.BeginEndWriteAsync(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
       at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageWriter.<WriteMessage>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageWriter.<WriteEvent>d__9`2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<>c__DisplayClass27_1`2.<<SendEvent>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.PowerShell.EditorServices.Utility.ThreadSynchronizationContext.RunLoopOnCurrentThread()
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()<---
    

2018-08-07 16:11:12.001 [ERROR] C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: In method 'ProtocolEndpoint_UnhandledException', line 437:
    PowerShell Editor Services is terminating due to an unhandled exception, see previous logs for details.

@rjmholt
Copy link
Contributor

rjmholt commented Aug 20, 2018

@JustinGrote yes I think this is the issue you were seeing too. It has to do with us changing to named pipes. I'll have a look into it

@rjmholt
Copy link
Contributor

rjmholt commented Aug 23, 2018

So my current theory is that VSCode might be closing the named pipe on its end. The problem is that VSCode has to create the named pipe and it has to do so in a certain way to keep the connection secure. So this one might take some work to fix...

But I'm not sure why the named pipe is closing.

@johnpankowicz
Copy link

I have the same issue whenever I attempt to use the Powershell Interactive Session launch configuration. I set a breakpoint and when it hits it, I stop debugging. I Immediately get the following error: "The PowerShell session has terminated due to an error, would you like to restart it?"
I am using VsCode 1.31.1 and Powershell extension 1.11.0. I tried using Powershell Preview extension 2.0.0. The same problem occurs.
When I install Powershell extension 1.7.0, the problem goes away.

@rjmholt rjmholt removed their assignment Mar 5, 2019
@rkeithhill
Copy link
Contributor

@johnpankowicz Can you attach a zip of the log files from a session that has terminated this way? See https://github.com/PowerShell/vscode-powershell/blob/master/docs/troubleshooting.md#logs for instructions.

@johnpankowicz
Copy link

@rkeithhill I upgraded version 1.7.0 back to 1.11.0. Now the problem does not occur! Before downgrading to 1.7.0, I had done a lot of testing on 1.11.0 and the Preview 2.0.0 to see under what conditions I would get or not get the problem. I couldn't find a case where it would NOT occur. The problem went away when I found and tried the suggestion above by @msturtz2017 to downgrade to 1.7.0.
I will let you know when and if the problem reappears.

@SydneyhSmith
Copy link
Collaborator

@johnpankowicz I will close the issue for now, please let us know if you begin encountering this again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants