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

Can't start remote debug server undefined method `wait_connection=' for Byebug:Module (NoMethodError) #185

Closed
jessesanford opened this issue Nov 9, 2015 · 7 comments

Comments

@jessesanford
Copy link

When I try to start the remote server following the guide I get the following with every version of byebug > 5.x:

undefined method `wait_connection=' for Byebug:Module (NoMethodError)

relevant code:

  require 'byebug'
  Byebug.wait_connection = true
  Byebug.start_server('localhost', 8989)
@guilherme
Copy link
Contributor

to help:

i've discovered that:

require 'byebug/core'
Byebug.wait_connection = true
Byebug.start_server('localhost', 8989)

works.

and if you try:

require 'byebug'
debugger
Byebug.wait_connection = true
Byebug.start_server('localhost', 8989)

works too.

It works because "debugger" calls: Byebug.attach(https://github.com/deivid-rodriguez/byebug/blob/master/lib/byebug/attacher.rb), which calls require 'byebug/core' which requires the remote part.

I wonder if: https://github.com/deivid-rodriguez/byebug/blob/master/lib/byebug.rb should require 'byebug/core' ?

@deivid-rodriguez
Copy link
Owner

Indeed. This was changed in b77855c to speed up library loading. I didn't notice that it would break remote debugging.

I thinking we could add another kernel method remote_byebug to make setting this up easier and less likely to break, that would do the whole

require 'byebug/core'
Byebug.wait_connection = true
Byebug.start_server('localhost', 8989)

For now, follow @guilherme's fix! 😃

@raphi
Copy link

raphi commented Jan 14, 2016

👍

@donnoman
Copy link

donnoman commented Jun 1, 2016

I had a hard time launching the remote debugger ONLY when I wanted it launched. It was further complicated that I got some other error when calling 'debugger' as one of the previous posters mentioned.

This is what I had to do, in order to start the debugger on a multi-process unicorn and connect to it with the byebug remote client.

I added the following to the class under test.

The order of the requires was important. Using the :: to denote top level class was also important.

  def self.remote_debugger
    require "byebug/core"
    port = begin
      server = TCPServer.new(nil, 0)
      server.addr[1]
    ensure
      server.close if server
    end
    puts "Remote debugger on port #{port}"
    ::Byebug.wait_connection = true
    ::Byebug.start_server('localhost', port)
    require "byebug"
  end

Now to trigger the debugger where I wanted it also in this class. I couldn't call 'debugger' here. I had to ::Byebug.byebug to avoid that naming conflict. This was deep in a mailer view with Rails and Devise.

  # http://stackoverflow.com/questions/14286601/resque-and-resque-mailer-with-devise
  def self.perform(action, *args)
    remote_debugger
    ::Byebug.byebug
    # Hack to prevent RuntimeError - Could not find a valid mapping for admin.attributes
    record_wrapper = args.shift
    record_hash = args.shift
...

I really wish the remote debugger server and client were reversed, or were supported in such a fashion. Such that I could just start the debugger cli listening at a specific port and it would wait until the app contacted it, it could debug then when done wait for the next debugger call.

Then in the app when triggering a breakpoint, it connects to the cli. That way it wouldn't matter which process was being debugged.

@donnoman
Copy link

donnoman commented Jun 2, 2016

I was able to revise my hack

  module Byebug
    class << self
      def start_remote_debugging
        require "byebug/core"
        require "byebug"
        port = begin
          server = TCPServer.new(nil, 0)
          server.addr[1]
        ensure
          server.close if server
        end
        "Remote debugger on port #{port}".tap do |message|
          puts message
          Rails.logger.warn message
        end
        self.wait_connection = true
        start_server('localhost', port)
        attach
      end
    end
  end

then later

def some_method_somewhere
  Byebug.start_remote_debugging
...

which spits out something like

Remote debugger on port 51737
bundle exec byebug -R 51737

@cben
Copy link
Contributor

cben commented Sep 27, 2016

@donnoman The TCPServer part is just to find an unused port, right?
After #277 gets merged you should be able to simply do

self.wait_connection = true
start_server('localhost', 0) do
  puts "Remote debugger on port #{Byebug.actual_port}"
end

@deivid-rodriguez
Copy link
Owner

This was improved via #406. Now you can use remote_byebug to start the remote debugger.

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

6 participants