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 · 19 comments
Open

Cannot connect to process running in Phusion Passenger #9

kmile opened this issue Mar 28, 2011 · 19 comments

Comments

@kmile
Copy link

kmile 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
Copy link
Owner

tmm1 commented Mar 28, 2011

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

@jodell
Copy link

jodell 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
Copy link
Owner

tmm1 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
Copy link

jodell commented Jun 21, 2011

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

@balepc
Copy link

balepc 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
Copy link
Owner

tmm1 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
Copy link

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
Copy link

dmitry 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
Copy link

glh1991 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
Copy link

swapab 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.

@shellandbull
Copy link

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

@swapab
Copy link

swapab 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
Copy link

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

@locofocos
Copy link

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
Copy link

ejholmes 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.

@zw963
Copy link

zw963 commented Mar 11, 2020

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

@gbxl
Copy link

gbxl commented Apr 20, 2020

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

@pgouv
Copy link

pgouv commented Apr 30, 2020

It doesnt work for me too.
I get Error: argument --pid (process already being traced?).

Passenger 5.1.12 and ruby 2.4.0

@krunde-nextpoint
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests