Debugging Async tasks yields `RuntimeError: running is given, but running`

Open
#486 13 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
devtools

Research direction

Reproduce the example with Ruby 3.1.0, rdbg 1.4.0, and async 2.0.0, using breakpoints on both puts calls. Start with debug/thread_client.rb around set_mode and wait_next_action_, then follow the breakpoint path through debug/breakpoint.rb. Done means the same asynchronous debugging flow continues without raising RuntimeError: running is given, but running.

Written by the indexing model from the issue text.

Description

Your environment

  • ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20]
  • rdbg -v: rdbg 1.4.0

Describe the bug

Debugging programs with the Async library often leads to RuntimeError: running is given, but running

To Reproduce

Install async 2.0.0:

gem install async

Create ruby script async_debug_test_case.rb as follows:

require 'async'

Async do |t|
  t.async do
    puts "1\n"
  end
  t.async do
    puts "2\n"
  end
end

Run rdbg, set breakpoints on both putss, and continue until error is raised. See output below:

rdbg scratch/async_debug_test_case.rb 
[1, 10] in scratch/async_debug_test_case.rb
=>   1| require 'async'
     2| 
     3| Async do |t|
     4|   t.async do
     5|     puts "1\n"
     6|   end
     7|   t.async do
     8|     puts "2\n"
     9|   end
=>#0    <main> at scratch/async_debug_test_case.rb:1
(rdbg) b 5    # break command
#0  BP - Line  /Users/machty/code/exc/rails/scratch/async_debug_test_case.rb:5 (line)
(rdbg) b 8    # break command
#1  BP - Line  /Users/machty/code/exc/rails/scratch/async_debug_test_case.rb:8 (line)
(rdbg) c    # continue command
[1, 10] in scratch/async_debug_test_case.rb
     1| require 'async'
     2| 
     3| Async do |t|
     4|   t.async do
=>   5|     puts "1\n"
     6|   end
     7|   t.async do
     8|     puts "2\n"
    10| end
=>#0    block in <main> (2 levels) at scratch/async_debug_test_case.rb:5
  #1    block in schedule at ~/.gem/ruby/3.1.0/gems/async-2.0.0/lib/async/task.rb:258

Stop by #0  BP - Line  /Users/machty/code/exc/rails/scratch/async_debug_test_case.rb:5 (line)
(rdbg) c    # continue command
[3, 11] in scratch/async_debug_test_case.rb
     3| Async do |t|
     4|   t.async do
     5|     puts "1\n"
     6|   end
     7|   t.async do
=>   8|     puts "2\n"
     9|   end
    10| end
    11| 
=>#0    block in <main> (2 levels) at scratch/async_debug_test_case.rb:8
  #1    block in schedule at ~/.gem/ruby/3.1.0/gems/async-2.0.0/lib/async/task.rb:258

Stop by #1  BP - Line  /Users/machty/code/exc/rails/scratch/async_debug_test_case.rb:8 (line)
1
(rdbg) c    # continue command
["DEBUGGER Exception: /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:986",
 #<RuntimeError: running is given, but running>,
 ["/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:115:in `set_mode'",
  "/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:698:in `wait_next_action_'",
  "/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:676:in `wait_next_action'",
  "/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:284:in `suspend'",
  "/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:217:in `on_breakpoint'",
  "/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/breakpoint.rb:65:in `suspend'",
  "/Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/breakpoint.rb:157:in `block in setup'",
  "scratch/async_debug_test_case.rb:8:in `block (2 levels) in <main>'",
  "/Users/machty/.gem/ruby/3.1.0/gems/async-2.0.0/lib/async/task.rb:258:in `block in schedule'"]]
  0.0s    error: Async::Task [oid=0x5c8] [ec=0x5dc] [pid=34553] [2022-01-12 04:52:04 -0400]
               |   RuntimeError: running is given, but running
               |   → /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:115 in `set_mode'
               |     /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:698 in `wait_next_action_'
               |     /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:676 in `wait_next_action'
               |     /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:284 in `suspend'
               |     /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/thread_client.rb:217 in `on_breakpoint'
               |     /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/breakpoint.rb:65 in `suspend'
               |     /Users/machty/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/gems/debug-1.4.0/lib/debug/breakpoint.rb:157 in `block in setup'
               |     scratch/async_debug_test_case.rb:8 in `block (2 levels) in <main>'
               |     /Users/machty/.gem/ruby/3.1.0/gems/async-2.0.0/lib/async/task.rb:258 in `block in schedule'

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.

Dominant language
Ruby
Stars
1.3k
Forks
146
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/debug

All issues in ruby/debug

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.