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

未关闭
#486 13 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
devtools

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Ruby
星标
1.3k
派生
146
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/debug 的其他 Issue

查看 ruby/debug 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。