Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always entering debugger in Ruby 2.7 (4.0.0.rc1) #690

Closed
riccardoporreca opened this issue Jan 6, 2022 · 6 comments · Fixed by #691 or #692
Closed

Always entering debugger in Ruby 2.7 (4.0.0.rc1) #690

riccardoporreca opened this issue Jan 6, 2022 · 6 comments · Fixed by #691 or #692

Comments

@riccardoporreca
Copy link
Collaborator

riccardoporreca commented Jan 6, 2022

When running htmlproofer 4.0.0.rc1 on Ruby 2.7, it seems to always trigger the debugger. This does not occur on Ruby 3.1.

I tested this in a reproducible way in a "fresh" Ruby installation using Docker via

docker run --rm -it ruby:2.7 bash
gem install html-proofer -v 4.0.0.rc1

Just asking for the version reveals the issue

$ ruby -v
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
$ htmlproofer -v
usr/local/lib/ruby/2.7.0/x86_64-linux/continuation.so: warning: callcc is obsolete; use Fiber instead
Debug.rb
Emacs support available.

/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:    if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
(rdb:1) n
/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:163:      if monitor_owned != (ow = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?)
(rdb:1) n
/usr/local/bundle/gems/zeitwerk-2.5.3/lib/zeitwerk/kernel.rb:36:      if required
(rdb:1) n
/usr/local/bundle/gems/zeitwerk-2.5.3/lib/zeitwerk/kernel.rb:37:        abspath = $LOADED_FEATURES.last
(rdb:1) n
/usr/local/bundle/gems/zeitwerk-2.5.3/lib/zeitwerk/kernel.rb:38:        if loader = Zeitwerk::Registry.loader_for(abspath)
(rdb:1) n
/usr/local/bundle/gems/zeitwerk-2.5.3/lib/zeitwerk/kernel.rb:42:      required
(rdb:1) n
/usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html_proofer.rb:21:module HTMLProofer
(rdb:1) n
/usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html_proofer.rb:56:gem_loader.eager_load
(rdb:1) n
/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:    if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
(rdb:1) n
/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:163:      if monitor_owned != (ow = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?)
(rdb:1) n
/usr/local/bundle/gems/html-proofer-4.0.0.rc1/bin/htmlproofer:9:require 'mercenary'
(rdb:1) n
/usr/local/bundle/gems/html-proofer-4.0.0.rc1/bin/htmlproofer:11:Mercenary.program(:htmlproofer) do |p|
(rdb:1) n
htmlproofer 4.0.0.rc1

UPDATE The same occurs with a yet more minimal example of simply requiring html-proofer

ruby -e "require 'html-proofer'"
@riccardoporreca riccardoporreca changed the title Always entering debuger in Ruby 2.7 (4.0.0.rc1) Always entering debugger in Ruby 2.7 (4.0.0.rc1) Jan 6, 2022
@riccardoporreca
Copy link
Collaborator Author

Even worse on Ruby 3.0.3, with an error raised

$ ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
$ ruby -e "require 'html-proofer'"
/usr/local/lib/ruby/3.0.0/debug.rb:6:in `<top (required)>': undefined method `>' for nil:NilClass (NoMethodError)
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /usr/local/bundle/gems/zeitwerk-2.5.3/lib/zeitwerk/kernel.rb:35:in `require'
        from /usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html_proofer.rb:18:in `block in <top (required)>'
        from /usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html_proofer.rb:17:in `each'
        from /usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html_proofer.rb:17:in `<top (required)>'
        from /usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html-proofer.rb:3:in `require_relative'
        from /usr/local/bundle/gems/html-proofer-4.0.0.rc1/lib/html-proofer.rb:3:in `<top (required)>'
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from -e:1:in `<main>'
<internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- html-proofer (LoadError)
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'

This seems to point to

%w[awesome_print debug].each do |gem|
require gem

where there is something related to debugging.

@riccardoporreca
Copy link
Collaborator Author

I also found a possibly related ruby/debug#275 and PR ruby/debug#278. I tried to give a go to the approach used in the PR (
https://github.com/ruby/debug/blob/2e5482064aa27d20d1432abf8e13ad064199ae9d/lib/debug/session.rb#L26-L28), as follows:

$ ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
$ ruby -e "\$LOADED_FEATURES << 'debug.rb'; require 'html-proofer'"

which does not error (nor enters the debugger on 2.7)

Hope this helps.

@riccardoporreca
Copy link
Collaborator Author

I can confirm requiring debug in

%w[awesome_print debug].each do |gem|
require gem

is the root cause of the issues in both Ruby 3.0 and 2.7

$ docker run --rm ruby:3.0.3 ruby -e "require 'debug'"
/usr/local/lib/ruby/3.0.0/debug.rb:6:in `<top (required)>': undefined method `>' for nil:NilClass (NoMethodError)
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'
$  docker run --rm ruby:2.7.5 ruby -e "require 'debug'"
/usr/local/lib/ruby/2.7.0/x86_64-linux/continuation.so: warning: callcc is obsolete; use Fiber instead
(rdb:1) Debug.rb
Emacs support available.

/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:    if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)

@gjtorikian
Copy link
Owner

I wonder why CI didn't complain about this? Thanks for finding it. I'm just going to comment the gem out, it's non-essential.

@riccardoporreca
Copy link
Collaborator Author

@gjtorikian, thanks for quick fix(es)!

I still see this happening with 4.0.0.rc2: I guess it is key to also prevent requiring debug in

%w[awesome_print debug].each do |gem|
require gem

Good point about CI... but it seems like entering the debugger does not bother the CI, but we still see it in the logs there, see the 4.0.0.rc2 jobs:

(Un)likely, 3.0.0 indeed just enters the debugger as 2.7.5 (could confirm locally with Docker), as opposed to the error I see with 3.0.3 does, which might have broken CI.

@gjtorikian
Copy link
Owner

Ohhh damn it, I understand what’s happening now. Ugh! Thank you for your patience.

@gjtorikian gjtorikian reopened this Jan 6, 2022
binarygit added a commit to binarygit/show-job that referenced this issue Jan 16, 2024
Requiring the debug gem caused the debugger to open in ruby 2.7
Here is an identical issue:
gjtorikian/html-proofer#690
binarygit added a commit to binarygit/show-job that referenced this issue Jan 16, 2024
Requiring the debug gem caused the debugger to open in ruby 2.7
Here is an identical issue:
gjtorikian/html-proofer#690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants