3

我通过工头启动独角兽,所以调试器提示被吞下。过去作为远程调试器连接时,我对debuggergem很幸运。

我们即将升级到 Ruby 2.1.2,据我了解,它与debugger.

我已将远程调试器代码更改为使用byebug

require 'byebug'

def find_available_port
  server = TCPServer.new(nil, 0)
  server.addr[1]
ensure
  server.close if server
end

port = find_available_port
puts "Remote debugger on port #{port}"
Byebug.start_server('localhost', port)

独角兽启动后,我可以连接到 byebug:

$ byebug -R localhost:54623
Connecting to byebug server localhost:54623
Connected.

但是我的代码中到处都是byebug调用,而且它们从不触发远程调试器中的断点。当调试器不是远程加载时,加载时阻塞的页面在远程连接时正常加载。

独角兽文件只指定了一名工人,所以我有理由确定不是这样:

require File.dirname(__FILE__)+'/application'

if Rails.env.development?
  worker_processes 1
  timeout_override = ENV['WEBSERVER_TIMEOUT_OVERRIDE']
  timeout Integer(timeout_override || 3600)
  if timeout_override
    puts "Development: Using WEBSERVER_TIMEOUT_OVERRIDE of #{timeout_override} seconds"
  end
else
  worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
  timeout 25
end

preload_app true

before_fork do |server, worker|

  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
      ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|

  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
      ActiveRecord::Base.establish_connection
end

任何想法将不胜感激。

4

1 回答 1

1

我认为您错过了一个简单的设置: Byebug.wait_connection = true

改变这个

port = find_available_port
puts "Remote debugger on port #{port}"
Byebug.start_server('localhost', port)

对此

port = find_available_port
puts "Remote debugger on port #{port}"
Byebug.wait_connection = true
Byebug.start_server('localhost', port)

这应该会变魔术。希望能帮助到你。

于 2014-12-21T08:07:48.727 回答