I launch unicorn through foreman, so the debugger prompt is swallowed. I've had luck with the debugger
gem in the past connecting as a remote debugger.
We're about to upgrade to Ruby 2.1.2 which, as I understand it, is not compatible with debugger
.
I've changed the remote debugger code to use 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)
Once unicorn is started, I can connect to byebug:
$ byebug -R localhost:54623
Connecting to byebug server localhost:54623
Connected.
But my code is littered with byebug
calls, and they never trigger a breakpoint in the remote debugger. Pages that block on load when the debugger is not remote load normally when connected remotely.
The unicorn file specifies only one worker, so I'm reasonably sure that's not it:
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
Any ideas would be greatly appreciated.