Skip to content

Instantly share code, notes, and snippets.

@stefan-mees
Last active December 25, 2015 19:19
Show Gist options
  • Save stefan-mees/122d88308bbe5e9e43ab to your computer and use it in GitHub Desktop.
Save stefan-mees/122d88308bbe5e9e43ab to your computer and use it in GitHub Desktop.
debug stuck ruby
require 'socket'
require 'timeout'
while true
Dir.glob('/home/ubuntu/applications/xx/shared/sockets/*.sock').each do |socket|
instance = $1 if socket =~ /([^\/]+)\.sock$/
s = nil
begin
Timeout.timeout(0.5) do
begin
s = UNIXSocket.new(socket)
s.send("GET /system/status HTTP/1.1\r\n\r\n", 0)
s.recv(1024*10)
s.close
rescue
s.close if s
raise
end
end
rescue
p $!
pid = open("/home/ubuntu/applications/xx/shared/pids/#{instance}.pid").read
p `echo "continue" | rvmsudo nrdebug #{pid}`
p `sudo strace -ttT -p#{pid} -o /tmp/strace_#{instance}_#{Time.now.to_i}.txt & sleep 30; kill $!`
end
end
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment