PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

Improve shutdown sequence of DebugAdapter

Open daviwil opened this issue 9 years ago • 5 comments

There is a timing issue with the shutdown sequence of the DebugAdapter which occasionally causes test hangs because the terminated event is not received. My guess is that this event never gets fully sent because of the timing of the shutdown sequence relative to some event handlers that get fired at that time. Compare the following two log files, the invocation state changes are interesting.

GoodRun.log.txt BadRun.log.txt

There are some additional notes in the BadRun.log.txt file at the end.

It's likely that the shutdown sequence will need to be rethought so that the order of events is predictable and all messages get sent before the process terminates.

daviwil avatar Jan 10 '16 23:01 daviwil

BTW in StdioClientChannel.cs I wonder if we should change wrap this call:

this.serviceProcess.Kill();

in a try/catch. I've observed this line throwing at times when running the unit tests (usually when I've screwed up something) because the service has already exited and then we try to kill it.

rkeithhill avatar Feb 28 '16 21:02 rkeithhill

Definitely, good point. I'll take that into account when I work on this. I've got some stuff I've already started to improve the async model so that CancellationTokens and failures flow through more easily (also with a fix for the CPU spin in MesaageReader). Will try to get that in for 0.5.0.

daviwil avatar Feb 28 '16 23:02 daviwil

I also notice this issue when I'm manually stepping through a unit test. By the time I get to the line that sends the DisconnectRequest, the process has already terminated. That results in an unhandled exception and causes the unit test to fail. These tests rarely (if ever) fail this way when when not run under the debugger but we gotta be able to debug unit tests, right. :-)

rkeithhill avatar Mar 01 '16 01:03 rkeithhill

Yeah, it needs to work correctly for sure. I keep seeing an annoying ThreadAbortException when running the tests in the debugger, is that what you're seeing too?

daviwil avatar Mar 01 '16 03:03 daviwil

I don't think that was what I was seeing but I was "experimenting" and likely causing the host to exit prematurely. :-)

rkeithhill avatar Mar 01 '16 05:03 rkeithhill