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

Cannot connect to process running in Phusion Passenger #9

Open
kmile opened this issue Mar 28, 2011 · 15 comments

Comments

Projects
None yet
@kmile
Copy link

commented Mar 28, 2011

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?

@tmm1

This comment has been minimized.

Copy link
Owner

commented Mar 28, 2011

passenger removes all signal handlers on startup. try require 'rbtrace' inside a before filer on ApplicationController instead.

@jodell

This comment has been minimized.

Copy link

commented Jun 21, 2011

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.

@tmm1

This comment has been minimized.

Copy link
Owner

commented Jun 21, 2011

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)

@jodell

This comment has been minimized.

Copy link

commented Jun 21, 2011

Unblocked, thanks! This also reminds me of the value of Bundler's 'require => false' option.

@balepc

This comment has been minimized.

Copy link

commented Aug 30, 2012

Still have a problem connecting to passenger instance :( It says
Error: argument --pid (pid is not listening for messages, did yourequire "rbtrace").

But, I've required it in before_filter and in envrionment.rb

@tmm1

This comment has been minimized.

Copy link
Owner

commented Aug 31, 2012

You need to ensure it is only required in the before_filter. Remove from environment.rb and make sure the Gemfile says :require => false

@saadbinakhlaq

This comment has been minimized.

Copy link

commented Nov 18, 2014

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

@dmitry

This comment has been minimized.

Copy link

commented Sep 6, 2015

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.

@glh1991

This comment has been minimized.

Copy link

commented Nov 26, 2015

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

@swapab

This comment has been minimized.

Copy link

commented Feb 10, 2016

@kmile were you able to make rbtrace work with passenger ?

I am having a hard luck in rbtraceing 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.
@mariogintili

This comment has been minimized.

Copy link

commented Apr 26, 2016

Getting the same issue as @swapnilabnave I'm using Rails 4.0.6

@swapab

This comment has been minimized.

Copy link

commented Apr 28, 2016

@mariogintili
I switched to memory_profiler which uses ObjectSpace to profile memory per request.

It helped me pin down leaks in my application.

@meetme2meat

This comment has been minimized.

Copy link

commented Jul 10, 2016

@tmm1 I getting the same error. But the only difference for me is that I'm using rbtrace on a standalone ruby application.

@locofocos

This comment has been minimized.

Copy link

commented Jul 27, 2016

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.

@ejholmes

This comment has been minimized.

Copy link

commented Nov 2, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.