Byebug Not Working - Rails

1. Byebug problem:

Recently while debugging a rails test with a byebug command, I noticed byebug had fired twice:

[39, 48] in /Users/.../text.rb

[39, 48] in /Users/.../text.rb
   39:   		[:from, :country]
   40:   	end
   41:
   42: 		def post_initialize
   43: 			byebug
=> 44: 			self.from ||= self.class.const_get('TRIAL_NUMBER_' + country)
   45: 	        self.twilio_client = Twilio::REST::Client.new
   46:   	end
   47:   end
   48: end


   39:   		[:from, :country]
   40:   	end
   41:
   42: 		def post_initialize
   43: 			byebug
=> 44: 			self.from ||= self.class.const_get('TRIAL_NUMBER_' + country)
   45: 	        self.twilio_client = Twilio::REST::Client.new
   46:   	end
   47:   end
   48: end

I had to Ctrl+C out of the frozen byebug REPL, which led to the following error:

Errno::ENOENT...connect(2)...DRb::DRbConnError

2. Cause of byebug problem:

As of rails 6, tests are run parallel by default.

Since multiple workers were executing my tests all at once, the workers all eventually reached the byebug statement in my test, which started multiple byebug REPLs at the same time, causing the byebug REPL to freeze.

3. Solution to frozen byebug REPL:

Only run one thread at a time when debugging a test with a byebug statement:

PARALLEL_WORKERS=1 rails test

Subscribe to Charlie Reese

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe