On irb:rdbg: IRB commands run in a different thread than the debugged program
还没有人认领这个 Issue。
评估
调研方向
Start with the IRB integration enabled by RUBY_DEBUG_IRB_CONSOLE and reproduce the issue using the shown .irbrc command and script.rb. Trace how commands entered in the irb:rdbg console are evaluated relative to the current debug frame and thread. Done means thread-local state is changed in the debugged program context, or an explicit opt-in is provided and covered by a regression test.
由索引模型根据 Issue 内容生成。
描述
Your environment
ruby -v: 3.3.7rdbg -v: 1.11.0- IRB integration: enabled
Describe the bug
When using debug with IRB integration (RUBY_DEBUG_IRB_CONSOLE=true), commands from IRB entered in the irb:rdbg console are evaluated on a different thread from the currently debugged program thread.
This causes problems when commands depend on thread-local data (Thread.current[:foo]), ActiveRecord::Base.connection (which may be bound per-thread), or other thread-local behaviors, like Apartment gem in our case.
To Reproduce
For example, having this on
# .irbrc
command = Class.new(IRB::Command::Base) do
category "Helpers"
description "Testing thread behaviour"
help_message "Testing thread behaviour"
define_method(:execute) do |arg|
puts "Modifying thread variables on: #{Thread.current.object_id}"
Thread.current[:testing_variable] = arg
end
end
IRB::Command.register "st", command
with this script
require 'debug'
require 'irb'
debugger;
x=1
Run
RUBY_DEBUG_IRB_CONSOLE=1 bundle exec ruby script.rb
As you can see in the image, the thread variable :testing_variable got modified on another thread different from the current session (1140 instead of 1120)
Expected behavior
When inside an interactive irb:rdbg session, commands should execute on the same thread and binding as the current debug frame (or at least provide a way to opt into that).
Additional context
This happened to us in a helper moving from binding.pry to debugger, the helper uses Apartment::Tenant.switch! from apartment gem which uses Thread variables to know in which tenant is currenly on
Because of this bug, the helper stop working and our state of the current_tenant on the debugger session gets corrupted, inside the db the schema_search_path is right but on the debugger the switch did not happen...
Questions
I’m not fully clear on how debug and IRB interact. I tried to trace where command execution is split so I could make an IRB command run in the debugger’s context, but I couldn’t figure it out. Could you briefly explain the execution flow?
- 主要语言
- Ruby
- 星标
- 1.3k
- 派生
- 146
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/debug 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 68/100
-
Support exceptionOptions in setExceptionBreakpoints to catch arbitrary exception classes via DAP 未关闭
难度 4/5 3-5 天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 52/100
-
难度 3/5 1-2 天 新手友好度 45/100
相似的 Issue
-
バグ
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 75/100
voxpupuli/puppet-epel#186 · 1 条评论 ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) 未关闭Bug Frontend
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 70/100
TheOdinProject/curriculum#31402 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100