On irb:rdbg: IRB commands run in a different thread than the debugged program
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- Ruby
- Stelle
- 1.3k
- Fork
- 146
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/debug
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Support exceptionOptions in setExceptionBreakpoints to catch arbitrary exception classes via DAP Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Issue simili
-
バグ
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Version bump for OpenVox 9 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
voxpupuli/puppet-epel#186 · 1 commento ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) ApertaBug Frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
TheOdinProject/curriculum#31402 · 1 commento ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100