Skip to content

Undefined method '+' for nil #1134

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

Open
paul opened this issue Feb 19, 2025 · 3 comments
Open

Undefined method '+' for nil #1134

paul opened this issue Feb 19, 2025 · 3 comments

Comments

@paul
Copy link

paul commented Feb 19, 2025

Your environment

  • ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
  • rdbg -v: rdbg 1.10.0

Describe the bug

I'm trying to debug a separate issue, where it seems the WebConsole thread is hanging instead of reporting an error. When I connect to the puma server with rdbg -A, do th to list the threads, then th 13 (or whatever to pick the stuck thread), then do bt, I get a big exception printed to the puma output:

[
  "DEBUGGER Exception: /home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/thread_client.rb:1252", 
  #<NoMethodError: undefined method '+' for nil>, 
  [
    "/home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/thread_client.rb:85:in 'DEBUGGER__::ThreadClient#default_frame_formatter'", 
    "/home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/thread_client.rb:755:in 'Method#call'", 
    "/home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/thread_client.rb:755:in 'DEBUGGER__::ThreadClient#frame_str'", 
    "/home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/thread_client.rb:742:in 'block in DEBUGGER__::ThreadClient#show_frames'", 
    "<internal:numeric>:257:in 'Integer#times'",
    # ...

(formatted for readability, such as it is)

Also, when this happens, the console input for rdbg doesn't return. I have to hit ^C, and it prints "Stop by SIGURG", and I'm able to input commands again.

To Reproduce

  1. Have a stuck thread using 100% CPU (I'm not sure that that's a requirement, its what I'm investigating).
  2. Connect rdbg to the process, and switch to the stuck thread.
  3. Print the backtrace for that thread.

Expected behavior

Successfully print the backtrace for a frame with nil for block_loc, or determine why a frame would have that.

Additional context

It looks like its coming from thread_client.rb:85, so I printed out the values for level, block_loc, args and frame:

{
  :level     => "",
  :block_loc => nil,
  :args      => [],
  :frame     => #<Object:ActionDispatch::ServerTiming:0x00045ba0
    attr_reader :callee = nil,
    attr_reader :local_variables = nil,
    binding = #<Binding:0x00007f67cf5e0e78>,
    class = ActionDispatch::ServerTiming < Object,
    dupped_binding = nil,
    frame_depth = 17,
    has_raised_exception = nil,
    has_return_value = nil,
    iseq = <RubyVM::InstructionSequence:block in call@/home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/actionpack-7.1.5.1/lib/action_dispatch/middleware/server_timing.rb:58>,
    location = "/home/rando/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/actionpack-7.1.5.1/lib/action_dispatch/middleware/server_timing.rb:24:in 'ActionDispatch::ServerTiming::Subscriber#collect_events'",
    raised_exception = nil,
    return_value = nil,
    self = #<ActionDispatch::ServerTiming:0x00007f67e8e5f1f8 ...wall of text, looks like a middleware stack...>,
    show_line = nil
  >
}

I'm able to get it to not blow up by changing the code like this:

-          "#{colorize_blue("block")}#{args_str} in #{colorize_blue(block_loc + level)}"
+          "#{colorize_blue('block')}#{args_str} in #{colorize_blue([block_loc, level].compact.join)}"

But, I'm not sure why block_loc is nil (and level is empty string), and if that indicates a larger problem.

@cguess
Copy link

cguess commented Mar 16, 2025

I'm seeing the same problem on my end.

@chaffeqa
Copy link

Ditto

@andrepiske
Copy link

andrepiske commented Apr 26, 2025

I'm seeing the same. I'm able to reproduce the bug with:

require 'debug'

class Whatever
  def some_method
    loop do
      begin
        raise "foo"
      rescue => e
        debugger
      end
    end
  end
end

Whatever.new.some_method

Just run it with ruby 3.4.1 and debug 1.10.0 and the error pops up. The issue doesn't happen with ruby 3.3.8.

It seems that the regexp approach introduced in https://github.com/ruby/debug/pull/91/files#diff-372c5559dee1ab1a9fa1bace23d908bca7e295bfd24f10906a866529a7be6bc7 is not enough to cover all cases.

For the ruby code above, the result of location.label in ruby 3.4.1 is the string "Kernel#loop", which doesn't match against the BLOCK_LABL_REGEXP regexp.

In ruby 3.3.8, location.label returns block in some_method which then matches against that regex.

I tested with ruby 3.5.0-preview1 and the string is also Kernel#loop, so it also fails to match against the regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants