Skip to content
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

Restart threads on DAP evaluation #950

Merged
merged 1 commit into from
Apr 1, 2023
Merged

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 29, 2023

This makes sure DAP evaluation request also doesn't hang.

See #947 for the original console implementation.

@st0012
Copy link
Member Author

st0012 commented Mar 29, 2023

@ono-max I tried implementing the same change for CDP as well but it still hangs. So I will leave that to you.

Note: I discovered some issues on a test helper when doing the above and opened #951 for it.

@st0012 st0012 mentioned this pull request Mar 29, 2023
@ko1
Copy link
Collaborator

ko1 commented Mar 30, 2023

Thank you for the report. But this patch is not acceptable because it doesn't stop other threads after the evaluation.

_th0 = Thread.new{loop{sleep 0.5; p :th0}}
_th1 = Thread.new{loop{sleep 0.5; p :th1}}
loop do
  sleep 0.5
  p :main
end

Please try the above code and evaluate something on the debug console.

@ko1 ko1 closed this Mar 30, 2023
@ko1 ko1 reopened this Mar 30, 2023
@ko1
Copy link
Collaborator

ko1 commented Mar 30, 2023

[master]$ git diff
diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb
index 8298428..bae1e4d 100644
--- a/lib/debug/server_dap.rb
+++ b/lib/debug/server_dap.rb
@@ -625,6 +625,7 @@ module DEBUGGER__
           expr = req.dig('arguments', 'expression')

           if find_waiting_tc(tid)
+            restart_all_threads
             request_tc [:dap, :evaluate, req, fid, expr, context]
           else
             fail_response req
@@ -701,6 +702,7 @@ module DEBUGGER__
         register_vars result[:variables], tid
         @ui.respond req, result
       when :evaluate
+        stop_all_threads
         message = result.delete :message
         if message
           @ui.respond req, success: false, message: message

could you add stop_all_threads?

This makes sure DAP evaluation request also doesn't hang.

See ruby#947 for the original console implementation.
@st0012
Copy link
Member Author

st0012 commented Mar 30, 2023

Ah I thought it's handled in Session#process_event too. I've updated code but will try to put up a test case for thread-stopping too.

test/protocol/eval_test.rb Outdated Show resolved Hide resolved
@st0012 st0012 force-pushed the followup-on-947 branch 3 times, most recently from d024286 to 076f56b Compare March 30, 2023 19:20
@st0012
Copy link
Member Author

st0012 commented Mar 30, 2023

I think I found another issue: when I run the test, the result was not deterministic even without sleep and fails around 10% of the time on my machine.

I initially thought it's because of my test, but then I found that it's because this early return isn't always correct. Sometimes it doesn't reflect the actual running thread count and thus the debugger doesn't stop the threads. If I comment it out, the test doesn't fail intermittently anymore. Should I address that in this PR too?

@ko1
Copy link
Collaborator

ko1 commented Mar 31, 2023

Now current behavior is already non-deterministic (by design).
Essentially this is hard to write a test for such cases.

@st0012
Copy link
Member Author

st0012 commented Mar 31, 2023

As the test could make CI unstable, I've dropped it.

@st0012 st0012 requested a review from ko1 March 31, 2023 13:49
@ko1 ko1 merged commit 61e378c into ruby:master Apr 1, 2023
@st0012 st0012 deleted the followup-on-947 branch April 3, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants