-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
fix: check if thread is still paused before handling stacktrace command result #1364
fix: check if thread is still paused before handling stacktrace command result #1364
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused about what kind of error behavior you're seeing. In the other issue you mention:
Sometimes it stops at some random spot in framework code, sometimes it shows error "Thread 1 is not paused".
Seems to me that this would only protect against the second scenario and that could probably be changed to:
diff --git a/lua/dap/session.lua b/lua/dap/session.lua
index 2bb16f5..435411b 100644
--- a/lua/dap/session.lua
+++ b/lua/dap/session.lua
@@ -744,11 +744,15 @@ function Session:event_stopped(stopped)
startFrame = 0,
threadId = stopped.threadId
}
local err, response = self:request('stackTrace', params)
if err then
- utils.notify('Error retrieving stack traces: ' .. utils.fmt_error(err), vim.log.levels.ERROR)
+ if thread.stopped then
+ utils.notify('Error retrieving stack traces: ' .. utils.fmt_error(err), vim.log.levels.ERROR)
+ else
+ log.debug("Debug adapter resumed during stopped event handling", thread, err)
+ end
return
end
local frames = response.stackFrames --[=[@as dap.StackFrame[]]=]
thread.frames = frames
local current_frame = get_top_frame(frames)
But I'm not sure how to fix the stopping at random-spot aspect.
Seems like in that case the stacktrace goes through, but the debug-adapter continues after? If that's the case, I don't see how that can be fixed on the client side at all - it's an inherent race.
For "Thread 1 is not paused" error, here is comment dart-lang/sdk#57006 (comment) from @DanTup
Maybe a standard error code is a way to handle it? The best solution would be to not show such an error, as it is not actionable. |
I'm unfamiliar with this code, but this logic sounds right to me. It's possible the stackTrace request succeeds, but there was a That said, I don't know if checking |
My concern is that even if it checks the stopped state again on a successful stacktrace response there's still a race if the debug adapter doesn't do any synchronization. If I understand it right, the debug adapter basically does:
nvim-dap is mostly single-threaded, with event loop based cooperative concurrency, so there are the following ways it can observe and react to the events:
Or:
With this PR these scenarios would be fine, but there's also:
I also don't see how the client could handle ^ even if it weren't for the threading model, at some point it must act on a given state and jump to the frame. It can't assume that there might be coming a debug adapter generated continue any second. (Note the PR here is fine for me, but if I understand the scenario right there's still a potential race left) |
Yes, I think in this case you have to jump to the stack frame. However when the |
738d05a
to
fa98e8c
Compare
Fixes mfussenegger#1363 Co-authored-by: Mathias Fussenegger <[email protected]>
f7c87e9
to
4ba9147
Compare
Fixes #1363