Open kmile opened 13 years ago
passenger removes all signal handlers on startup. try require 'rbtrace'
inside a before filer on ApplicationController
instead.
I'm having the same issue under Sinatra. I've tried instrumenting the require statement in a controller action, app load, and the rackup file independently but it doesn't take. A simple ruby script works with rbtrace on the same machine. Using ruby 1.9.2 and passenger 3.0.6.
If you're using gem 'rbtrace'
in a Gemfile, rbtrace will be loaded before passenger forks. You need to make sure it is loaded in the controller action (require
should return true
)
Unblocked, thanks! This also reminds me of the value of Bundler's 'require => false' option.
Still have a problem connecting to passenger instance :( It says
Error: argument --pid (pid is not listening for messages, did you
require "rbtrace").
But, I've required it in before_filter and in envrionment.rb
You need to ensure it is only required in the before_filter. Remove from environment.rb and make sure the Gemfile says :require => false
Hi @tmm1 I am following up on this blog http://blog.skylight.io/hunting-for-leaks-in-ruby/, I have created an endpoint in admin namespace and request that endpoint I am getting this error in the logs
Error: argument --pid (process already being traced?).
Error: argument --pid (pid is not listening for messages, did you
require "rbtrace").
this is like alternating
my configuration
Gemfile
gem 'rbtrace', require: false
controller.rb file
class Admin::InvestigationsController < AdminController
defaults resource_class: User
def memory
system("rbtrace -p #{Process.pid} -e 'load \"#{Rails.root}/script/heap_dump.rb\"'")
end
end
initializers/users.rb
require 'rbtrace'
This setup worked fine if I ran rbtrace from the console but I am getting the above errors when I run it from the endpoint.
it would be great if you would please have a look
Thanks
It works well then using gem 'rbtrace', require: false
and then require 'rbtrace'
somewhere in before_filter
(for example, in ApplicationController
). Looks like can be closed, but noticed somewhere in the README.
I am trying to perform an rbtrace on a Rails app running in puma, add gem 'rbtrace', '~> 0.4.7', require: false in Gemfile, and add require 'rbtrace' in config/environment.rb. then what should i do for listenning the pid. Thanks
@kmile were you able to make rbtrace
work with passenger ?
I am having a hard luck in rbtrace
ing mine.
1.Added controller action to get a heap dump
def dump
require 'rbtrace'
pid = Process.pid
Rails.logger.debug("Process.pid: #{pid}")
system("rbtrace -p #{pid} -e 'Thread.new{require \"objspace\"; ObjectSpace.trace_object_allocations_start; GC.start(); ObjectSpace.dump_all(output: File.open(\"/tmp/dump/heap_dump_#{params[:id]}.json\", \"w\"))}.join'")
head :ok
end
2.required rbtrace
before each action
before_filter :require_rbtrace
def require_rbtrace
require 'rbtrace'
end
3.In boot.rb --> require 'rbtrace'
4.Call the dump
action https://bingdev.bingoa.com/api/feeds/dump?id=11
Still see Error: argument --pid (pid is not listening for messages, did you require "rbtrace")
App 17680 stderr: Error: argument --pid (pid is not listening for messages, did you `require "rbtrace"`).
App 17680 stderr: Try --help for help.
Getting the same issue as @swapnilabnave I'm using Rails 4.0.6
@mariogintili I switched to memory_profiler which uses ObjectSpace to profile memory per request.
It helped me pin down leaks in my application.
@tmm1 I getting the same error. But the only difference for me is that I'm using rbtrace
on a standalone ruby application.
I was having this same issue- the given pid was not listening for messages. What ultimately worked for me was putting the code from the Thread.new command into a controller method by itself:
def memory_dump
GC.start
require 'objspace'
io=File.open('/tmp/ruby-heap.dump', 'w')
ObjectSpace.dump_all(output: io)
io.close
render text: 'Memory dump complete!'
end
then I created a route to this action and navigated to it in my browser. This completed successfully.
For anyone running into this issue, the correct way to use rbtrace with recent versions of passenger is to require it within the after_installing_signal_handlers
hook:
# config.ru
PhusionPassenger.on_event(:after_installing_signal_handlers) do
require 'rbtrace'
end
If you require it earlier, passenger resets all signal handlers after fork, which removes the SIGURG
handler that rbtrace installs.
For anyone running into this issue, the correct way to use rbtrace with recent versions of passenger is to require it within the
after_installing_signal_handlers
hook:# config.ru PhusionPassenger.on_event(:after_installing_signal_handlers) do require 'rbtrace' end
If you require it earlier, passenger resets all signal handlers after fork, which removes the
SIGURG
handler that rbtrace installs.
It working. passenger 6.0.2, ruby 2.6.1
Is that before or after the run Rails.application
? I have tired both, with passenger 6.0.2
and no dice.
I tired both the main passenger PID as well as individual workers' pid :(
After adding require: false
in Gemfile
it works!
For posterity, here is the full setup:
passenger 6.0.2
rails (6.0.1)
ruby 2.5.0p0
In gemfile:
gem 'rbtrace', require: false
In config.ru, at the very top:
PhusionPassenger.on_event(:after_installing_signal_handlers) do
require 'rbtrace'
end
It doesnt work for me too. I get Error: argument --pid (process already being traced?).
Passenger 5.1.12 and ruby 2.4.0
I am getting the same error "argument --pid (process already being traced?)" as well. I am on: Passenger: 6.0.3 Ruby: 2.6.6 Rails: 5.2.4.4 Nginx: 1.17.10
I am trying to perform an rbtrace on a Rails app running in Phusion Passenger. If I execute a long running rake task it can connect just fine. If I connect it to the corresponding Passenger Process it tells me (pid is not listening for messages, did you
require "rbtrace"
).I have required rbtrace in the environment.rb. Passenger runs in production mode, and I am using REE 1.8.7. Is there any reason rbtrace would not work for a Passenger process?