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

Infinite recursion (SystemStackError) on load when running with -rdebug with breakpoints #1107

Closed
native-api opened this issue Jan 3, 2020 · 2 comments

Comments

@native-api
Copy link

Basic Info

  • Faraday Version: 0.17.3, 1.0.0
  • Ruby Version: 2.5.3, 2.6.3

Issue description

Whenever I run Ruby with -rdebug and set a breakpoint, the interpreter quits with SystemStackError upon loading Faraday.

This makes it impossible to debug any program that uses the library.

Steps to reproduce

(For Ruby 2.5.3 and Faraday 0.17.3, the result is the same)

$ cat test.rb
require 'faraday'
puts "bla-bla-bla"

$ ruby -rdebug test.rb 
/home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/x86_64-linux/continuation.so: warning: callcc is obsolete; use Fiber instead
Debug.rb
Emacs support available.

test.rb:1:require 'faraday'
(rdb:1) b 2
Set breakpoint 1 at test.rb:2
(rdb:1) c
Traceback (most recent call last):
	2: from test.rb:1:in `<main>'
	1: from /home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- faraday (LoadError)
	9360: from test.rb:1:in `<main>'
	9359: from /home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
	9358: from /home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
	9357: from /home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
	9356: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:21:in `<top (required)>'
	9355: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:126:in `<module:Faraday>'
	9354: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:102:in `default_adapter='
	9353: from /home/vmuser/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/debug.rb:1109:in `block in <class:DEBUGGER__>'
	 ... 9348 levels...
	   4: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:115:in `method_missing'
	   3: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:115:in `method_missing'
	   2: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:115:in `method_missing'
	   1: from /home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:115:in `method_missing'
/home/vmuser/.rvm/gems/ruby-2.6.3/gems/faraday-1.0.0/lib/faraday.rb:115:in `method_missing': stack level too deep (SystemStackError)
@iMacTia
Copy link
Member

iMacTia commented Jan 9, 2020

@native-api thanks for raising this issue and apologies for the slow reply but this took some time to investigate!

@olleolleolle @technoweenie this is a curious one. I spent some time reproducing and I noticed the method_missing at the bottom of the backtrace.
I was able to change the method_missing implementation in Faraday to print the name of the method being called. To my surprise, the result was default_connection being printed every time.

Now, I presume this has something to do with class << self being used, but default_connection getter being defined outside (only the setter, or attr_writer is defined inside).
So I tried moving the definition in, which fixes the SystemStackError, but causes another one:

Traceback (most recent call last):
	11: from test.rb:2:in `<main>'
	10: from test.rb:2:in `require'
	 9: from /Users/mattiagiuffrida/Development/RubymineProjects/gems/faraday/lib/faraday.rb:16:in `<top (required)>'
	 8: from /Users/mattiagiuffrida/Development/RubymineProjects/gems/faraday/lib/faraday.rb:130:in `<module:Faraday>'
	 7: from /Users/mattiagiuffrida/Development/RubymineProjects/gems/faraday/lib/faraday.rb:88:in `default_adapter='
	 6: from /Users/mattiagiuffrida/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/debug.rb:1109:in `block in <class:DEBUGGER__>'
	 5: from /Users/mattiagiuffrida/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/debug.rb:865:in `trace_func'
	 4: from /Users/mattiagiuffrida/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/debug.rb:801:in `check_break_points'
	 3: from /Users/mattiagiuffrida/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/debug.rb:801:in `each'
	 2: from /Users/mattiagiuffrida/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/debug.rb:805:in `block in check_break_points'
	 1: from /Users/mattiagiuffrida/Development/RubymineProjects/gems/faraday/lib/faraday.rb:95:in `respond_to?'
/Users/mattiagiuffrida/Development/RubymineProjects/gems/faraday/lib/faraday.rb:102:in `default_connection': uninitialized constant Faraday::Connection (NameError)

I won't have time to continue on it today, but if you guys have some spare time at least you have a good starting point 😃
@native-api your help would also be appreciated if you could find some time to test alternative solutions

@iMacTia
Copy link
Member

iMacTia commented Nov 13, 2020

Fixed in #1205 🎉
Thanks again @native-api for all the research 🙏

@iMacTia iMacTia closed this as completed Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants