Skip to content

Debugging hangs when stepping through a while loop #156

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
vsccarl opened this issue Apr 22, 2016 · 11 comments
Closed

Debugging hangs when stepping through a while loop #156

vsccarl opened this issue Apr 22, 2016 · 11 comments

Comments

@vsccarl
Copy link

vsccarl commented Apr 22, 2016

Code Version: 1.0.1-alpha
OS: Windows 10

Repro Steps:

  1. Add the below code
  2. Add breakpoints on line 4 and line 22
  3. Add "str" to watch (not '$str')
  4. Start debugging
  5. Continue to hit the breakpoint on line 4
  6. Step-over in the while loop, then slowly step-over through the while loop

Actual:
Debugging hangs and will not allow you to continue or step-over. When pushing stop and error pops up saying Canceled. Sometimes an error shows "Debug adapter process has terminated unexpectedly."

function Write-Item($itemCount) {
    $i = 1

    while ($i -le $itemCount) {
        $str = "Output $i"
        Write-Output $str

        # In the gutter on the left, right click and select "Add Conditional Breakpoint"
        # on the next line. Use the condition: $i -eq 25
        $i = $i + 1

        # Slow down execution a bit so user can test the "Pause debugger" feature.
        Start-Sleep -Milliseconds 100
    }
}

# Do-Work will be underlined in green if you haven't disable script analysis.
# Hover over the function name below to see the PSScriptAnalyzer warning that "Do-Work"
# doesn't use an approved verb.
function Do-Work($workCount) {
    Write-Output "Doing work..."
    Write-Item $workcount
    Write-Host "Done!"
}

Do-Work 50

@rkeithhill
Copy link
Contributor

Thanks for the repro. It seems that the key is the watched expression that fails to evaluate. Changing to str to $str works fine because $str evaluates without an error. It seems there is something about us evaluating an invalid expression that is wedging the debugger.

@rkeithhill
Copy link
Contributor

And it really has nothing to do with the watch window. It is merely executing script that generates errors. Remove the watch and put str on line 12. Same thing happens after a while of stepping. The debugger wedges. :-(

I guess that is one way to teach folks not to write code that generates errors. :-)

@daviwil
Copy link
Contributor

daviwil commented Apr 25, 2016

Gonna mark this as an issue to investigate for 0.6.0

@daviwil daviwil added the Issue-Bug A bug to squash. label Apr 25, 2016
@daviwil daviwil added this to the 0.6.0 milestone Apr 25, 2016
@rkeithhill
Copy link
Contributor

rkeithhill commented Apr 29, 2016

If I step really, really fast after a while a while the debug host crashes with:

    FATAL UNHANDLED EXCEPTION:

    System.InvalidOperationException: The collection has been marked as complete with regards to additions.
       at System.Collections.Concurrent.BlockingCollection`1.TryAddWithNoTimeValidation(T item, Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Collections.Concurrent.BlockingCollection`1.Add(T item)
       at Microsoft.PowerShell.EditorServices.Utility.ThreadSynchronizationContext.Post(SendOrPostCallback callback, Object state) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\ThreadSynchronizationContext.cs:line 42
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.SendEvent[TParams](EventType`1 eventType, TParams eventParams) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs:line 175
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<DebugService_DebuggerStopped>d__30.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs:line 538
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()

4/28/2016 9:23:53 PM [ERROR] - Method "CurrentDomain_UnhandledException" at line 178 of C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Host\Program.cs

    FATAL UNHANDLED EXCEPTION:

    System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter.StackFrame.Create(StackFrameDetails stackFrame, Int32 id) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\DebugAdapter\StackFrame.cs:line 37
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<HandleStackTraceRequest>d__25.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs:line 400
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__32.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs:line 279
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<ListenForMessages>d__31.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs:line 226
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncContext.cs:line 48
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContextThread.<>c__DisplayClass4_0.<Run>b__0() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncContextThread.cs:line 65
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at System.Threading.Tasks.Task.Wait()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.WaitForExit() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs:line 79
       at Microsoft.PowerShell.EditorServices.Host.Program.Main(String[] args) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Host\Program.cs:line 168
    ---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter.StackFrame.Create(StackFrameDetails stackFrame, Int32 id) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\DebugAdapter\StackFrame.cs:line 37
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<HandleStackTraceRequest>d__25.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs:line 400
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__32.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs:line 279
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<ListenForMessages>d__31.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs:line 226
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncContext.cs:line 48
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContextThread.<>c__DisplayClass4_0.<Run>b__0() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncContextThread.cs:line 65
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter.StackFrame.Create(StackFrameDetails stackFrame, Int32 id) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\DebugAdapter\StackFrame.cs:line 37
       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<HandleStackTraceRequest>d__25.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\Server\DebugAdapter.cs:line 400
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__32.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs:line 279
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<ListenForMessages>d__31.MoveNext() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs:line 226
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc) in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncContext.cs:line 48
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContextThread.<>c__DisplayClass4_0.<Run>b__0() in C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncContextThread.cs:line 65
       at System.Threading.Tasks.Task.Execute()<---
    <---

Is there any form of pacing between the client and host to prevent client requests from getting too backed up? If I step slowly, it haven't gotten it to crash yet.

Also with the latest VSCode alpha, I haven't repro'd this with the DebugTest.ps1 in the examples dir. However if you add a watch for $str, set a breakpoint on $i = 1, press F5, hit the breakdpoint, then just keep F10 pressed - it should crash. Usually around Output 13 or 14 for me.

Watch out if you keep the F10 key pressed for too long after the debugger exits. You'll get a VSCode Error Canceled sometimes followed by an Error write EPIPE.

@daviwil daviwil modified the milestones: 0.7.0, 0.6.0 May 11, 2016
@daviwil
Copy link
Contributor

daviwil commented May 11, 2016

Hmm... I haven't been able to reproduce this issue in the latest state of everything, even with the repro hints that Keith added.. I'm going to move this to 0.7.0 to give a little more time for investigation.

@rkeithhill
Copy link
Contributor

Still repros for me. I pretty much press F10 after it hits the breakpoint and it sometimes wedges. See the attached debug log.

DebugAdapter.txt

This part of the log looks suspect:

5/15/2016 12:22:18 PM [VERBOSE] - Method "ReadMessage" at line 111 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs

    READ MESSAGE:

    {
      "type": "request",
      "seq": 804,
      "command": "next",
      "arguments": {
        "threadId": 1
      }
    }

5/15/2016 12:22:18 PM [VERBOSE] - Method "WriteMessage" at line 58 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs

    WRITE MESSAGE:

    {
      "type": "response",
      "request_seq": "804",
      "command": "next",
      "success": true,
      "body": null
    }

5/15/2016 12:22:18 PM [VERBOSE] - Method "WriteMessage" at line 58 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs

    WRITE MESSAGE:

    {
      "type": "response",
      "request_seq": "804",
      "command": "next",
      "success": true,
      "body": null
    }

Notice the two writes with seq number 804. Could be a glitch with logging. If not, could that mess up vscode?

@daviwil daviwil modified the milestones: 0.7.0, Backlog Aug 18, 2016
@TylerLeonhardt
Copy link
Member

I'm having trouble reproing this. It might be fixed. Can anyone repro the issue?

@rkeithhill
Copy link
Contributor

When I say press F10 above, what I really mean is press and hold F10.

@TylerLeonhardt
Copy link
Member

Worked on macOS but I did experience a hang on my Windows VM.

@rkeithhill
Copy link
Contributor

Good ol' monkey testing FTW. BTW I believe we should close this issue. I've tried the repro instructions and the original issue no longer repros. Then we should open a new issue along the lines of "Stepping too fast in the debugger causes a hang on Windows".

@TylerLeonhardt
Copy link
Member

I agree.

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

No branches or pull requests

4 participants