-
Notifications
You must be signed in to change notification settings - Fork 127
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
Debugging Async tasks yields RuntimeError: running is given, but running
#486
Comments
I think the debugger generally is not fiber-safe due to the current design. I also found #490 when debugging this issue. |
Now Fiber is not supported well. |
It is the same for the FiberScheduler, as I can see it: VSCode debugger breakpoints that get set within a fiber are not only never reached, the fibers don't even run It will be pretty awesome if we can use fibers and debug together, but with this limitation in mind I can work around it for my debugging. Anyway I am not sure if
|
ruby/debug#490 ruby/debug#486 Hopefully soon we can use fibers and debug gem together, but for now we will have to build testable code so that we can debug inside of tests. Signed-off-by: Kingdon Barrett <kingdon@weave.works>
I ran into this issue while upgrading an app from Ruby 2.7.6 to 3.1.2, also Async 1.30.3 to 2.0.3, even when not invoking the debugger. I'm able to work around the issue by removing I assume there will be some rough edges as Fibers continue to gain support, so no worries. It sounds like it may be a heavy lift for the debugger (re: the comment above "debugger generally is not fiber-safe due to the current design") but I'm curious if anyone knows of a workaround, perhaps a different debugger gem for now? I'm also happy to provide additional details if there's interest in working on this. I'll also ping the Socketry org that works on Async as well to see if anyone has ideas. Thank you! |
Just a note from @st0012's suggestion to test |
Under Ruby 3.2.2 while running several This leads to keyboard input being sent to different fibers on each keystroke, for example typing
So the only way to interact with the tasks using the IRB prompt is to double type each character. Being able to detect that multiple Going even further, it seems like an ideal flow would be allow users to select which task/fiber they're interacting with (dRB-style) when debugging, but of course I have no idea if this is realistic or feasible. |
If you want to run a
This will prevent multiple sessions or any async code from running. It will also prevent you from running async code from within the IRB session. If you want more fine grained control, you could use a mutex
This will only allow one |
class ThreadClient
def self.current
if thc = Thread.current[:DEBUGGER__ThreadClient]
thc
else
thc = SESSION.get_thread_client
Thread.current[:DEBUGGER__ThreadClient] = thc
end
end seems wrong. |
@ioquatix The Wouldn't it make sense to hook into As a side note |
When you enter Regarding 3.times do
Thread.new{binding.irb}
end
# Similar issues to:
```ruby
Async do |task|
3.times do
task.async{binding.irb}
end
end I would say that class IRB::Session
def initialize(input = $stdin, output = $stdout) # ...
@guard = Thread::Mutex.new
# ...
end
def run
# Only one thread/fiber can enter here:
@guard.synchronize{... run the actual UI ...}
end
GLOBAL = new
end
def binding.irb
IRB::Session::GLOBAL.run
end Or something to that effect... |
Hello, I just hit the same issue, coming around from socketry/async#225. I use ruby 3.1. Reading the thread, I have the same problem as @trevorturk. I'm not trying to run debug and I don't have any breakpoints set, yet I get a debugger error. My current work around is
when I want to debug. I'd be ok with knowing I cannot debug async code, but being able to load my code without triggering this error. |
Your environment
ruby -v
: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20]rdbg -v
: rdbg 1.4.0Describe the bug
Debugging programs with the Async library often leads to
RuntimeError: running is given, but running
To Reproduce
Install
async
2.0.0:Create ruby script
async_debug_test_case.rb
as follows:Run rdbg, set breakpoints on both
puts
s, and continue until error is raised. See output below:Expected behavior
Debugging should not crash.
Additional context
I can't replicate this issue using pure Fibers, so I suspect this has something to do with Ruby's new Fiber Scheduler interface and the way the Async library uses it. Note that simpler test cases using a single test cases involving one task don't seem to cause the rror.
The text was updated successfully, but these errors were encountered: