Rails Passenger Connection Refused Issue Solved

The OpenShift forums have been retired.
You can still read and search them, but for help, please post a question on Stack Overflow.

I guess that most of you have seen that error in their logs. At first I started wondering what was it all about.

/opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-scripts/prespawn:105:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)

It often results in the following message being displayed on your page, and which is the only debugging info which you are going to get from your browser.

We are sorry, but something went wrong!

It turn out that it has to do something with assets. I started digging on it I found that it is generated when Rails can't find the assets you are looking for because of either they are missing or they are not compiled or they are are not included in a manifest (directly by name or indirectly via require_tree).

The first case is clear. You should include them in your app's code or you should add them to your gear. The second case shouldn't be a problem for you, because OpenShift does that for you. But if you do have a problem with that, search the forum for issues regarding not compiling your assets.

The third case has two solutions. There is a right one and quick one. I'll need an expert's opinion about the second one. Here they are: You need to add the asset (usually a stylesheet and/or some third-party tool) to the list of items to precompile in the environment application.rb.

config.assets.precompile += ['960sm.css']

Or the quick way I found, which will work universally for all your assets:
There is a setting in the config/environments/production.rb

config.assets.compile = true Set it to true like that and this should solve the problem.

This is a copy of the originally logged error:

/opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-scripts/prespaw
n:105:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-sc
ripts/prespawn:105:in `new'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-sc
ripts/prespawn:105:in `connect'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-sc
ripts/prespawn:86:in `socket'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-sc
ripts/prespawn:90:in `head_request'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.12/helper-sc
ripts/prespawn:145:in `<main>'

I hope this helps. I spent two weeks digging on the same problem.

Thank you for your post! I'm sure it will help those that run into a similar scenario.

Cheers; ~Nam

Hi,

I tried with config.assets.compile = true and it didn't work. Still getting "We're sorry, but....".

I'm not using any database at the moment, but could it be that default setup of new app which is using sqlite3 is what is causing the problems?

My app works normal on my localhost, but when i upload it to OpenShift, I keep getting error "We're sorry, but....".

Pls, help!

@TheZhorzh, try checking the apache/passenger logs to see what errors you are getting.
You can either do an rhc app tail -a $app and restart your app server or then ssh into your app's gear
and then check the log files in the ~/ruby-1.{8,9}/logs directory.

HTH

Hello.

I am also seeing the same error.

I have done all these steps:

config.assets.precompile += ['960sm.css'] config.assets.compile = true Set it to true like that and this should solve the problem.

But nothing has changed. I am still geting this error:

ruby-1.9/logs/error_log-20130220-000000-EST <==
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `connect'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:86:in `socket'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:90:in `head_request'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:145:in `<main>'
/opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `new'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `connect'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:86:in `socket'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:90:in `head_request'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:145:in `<main>'
 
==> ruby-1.9/logs/error_log-20130221-000000-EST <==
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `connect'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:86:in `socket'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:90:in `head_request'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:145:in `<main>'
/opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `new'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `connect'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:86:in `socket'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:90:in `head_request'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:145:in `<main>'
 
==> ruby-1.9/logs/production.log <==
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/utils.rb:470:in `safe_fork'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/rack/application_spawner.rb:64:in `spawn_application'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:264:in `spawn_rack_application'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/passenger-spawn-server:102:in `<main>' 

I am also getting this error still with the advised fix. Itehnological do you have any other suggestions?

Hello,

I just experienced similar issue with my application (snippet of my error_log-20130322-000000-EST):

[Fri Mar 22 14:22:52 2013] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:openshift_t:s0:c3,c85
[Fri Mar 22 14:22:52 2013] [notice] mod_bw : Memory Allocated 32 bytes (each conf takes 32 bytes)
[Fri Mar 22 14:22:52 2013] [notice] mod_bw : Version 0.8 - Initialized [1 Confs]
[Fri Mar 22 14:22:52 2013] [notice] Digest: generating secret for digest authentication ...
[Fri Mar 22 14:22:52 2013] [notice] Digest: done
[Fri Mar 22 14:22:52 2013] [notice] Apache/2.2.15 (Unix) Phusion_Passenger/3.0.17 configured -- resuming normal operations
/opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `new'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:105:in `connect'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:86:in `socket'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:90:in `head_request'
    from /opt/rh/ruby193/root/usr/share/gems/gems/passenger-3.0.17/helper-scripts/prespawn:145:in `<main>'

Solution was simple:

1) login to your gear via SSH
2) cd ruby-1.9/repo
3) rm public/assets/*
4) RAILS_ENV=production rake assets:precompile
5) ls -l public/assets/

it should show all compiled assets

6) Restart application

Implications of "config.assets.compile = true" in production are explained at: http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not

Please note if you use gem like 'yui-compressor' it is required to have java installed on your application gear:

java -version
java version "1.7.0_19"
OpenJDK Runtime Environment (rhel-2.3.9.1.el6_4-i386)
OpenJDK Server VM (build 23.7-b01, mixed mode)

I came across this issue after registering with Open Shift and selecting the button to "deploy my first application!" Turns out deployment wasn't quite as easy as that.

This quickstart guide (https://www.openshift.com/kb/kb-e1005-ruby-on-rails-openshift-quickstart-guide) outlined my solution: I needed to add .openshift/action_hooks, which I copied from the quickstart github repository, as well as change the database configuration.

Here's the quickstart github repository: https://github.com/openshift/rails-example/

hi thanks for the post and suggestions i am trying to deploy my first rails app in openshift and getting the same error passenger connection refused. I tried changing the asset_precompile=true in production.rb file under config folder , restart my app then also tried the suggestion from Boris Mironov followed all his steps still am getting the same error in my rhc tail command is there any other option to fix this. any help appreciated thanks for all your info in the post. I searched further on google and came across this bugzilla thread for open shift https://bugzilla.redhat.com/show_bug.cgi?id=984867 As per the final update on nov 2013 is a known bug and the fix is to pass connection directly to apache instead of passenger .please find the following suggestions

  1. The request must be made against the Apache which runs on the Gear
  2. The correct port must be specified
  3. The Host header must be processed correctly. thanks if any updates please do reply back.

The question is, is there a work around for the mentioned bug? AFAIK I don't have access to the Apache configuration for my app. so how can I change this?

I'll reach out to our team and see if I can put something together for everyone.

@niharvey, thanks. A fix/workaround would be much appreciated. Asaiu all Passenger based apps on the ruby 1.9 cartridge are broken.

We've got the issue nailed down and we're looking into a few options to fix it. I'll keep updating this thread as information becomes available but for anyone who's interested in following the bug directly you can do so here https://bugzilla.redhat.com/show_bug.cgi?id=984867.

Awesome thanks :-)