On irb:rdbg: IRB commands run in a different thread than the debugged program
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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?
- Langage dominant
- Ruby
- Étoiles
- 1.3k
- Forks
- 151
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ruby/debug
-
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
-
Support exceptionOptions in setExceptionBreakpoints to catch arbitrary exception classes via DAPPeut-être pris @rira100000000 l’a pris il y a 115 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
-
Missing DAP OutputEvents for debuggee stdout/stderrPeut-être pris @vitallium l’a pris il y a 336 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
Toutes les issues de ruby/debug
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
openfoodfoundation/openfoodnetwork#15070 ·
Les mainteneurs répondent en général sous 2 jours
-
agent:triaged bug bughunt pm:bundler priority:p1 ux
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
SocketDev/socket-patch#2326 ·
Les mainteneurs répondent en général sous 1 jour
-
Remove sidekiq trace filteringOuverteinstrumentation-sidekiq
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
open-telemetry/opentelemetry-ruby-contrib#2735 ·
Les mainteneurs répondent en général sous 2 jours
-
Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
majorsilence/Reporting#703 ·
Les mainteneurs répondent en général sous 1 jour
-
SecureRandom.alphanumeric can silently return an empty or wrong-length secret instead of raisingOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
ruby/securerandom#92 ·