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

nginx processes are not cleaned up correctly in development #3

Closed
csuhta opened this issue Sep 7, 2013 · 7 comments
Closed

nginx processes are not cleaned up correctly in development #3

csuhta opened this issue Sep 7, 2013 · 7 comments

Comments

@csuhta
Copy link

csuhta commented Sep 7, 2013

In development, nginx processes are not stopped when I Ctrl+C in foreman.

Here's relevant vars from my .env:

RAILS_ENV=development
RACK_ENV=development
PASSENGER_MAX_POOL_SIZE=3
PORT=8080

and Procfile:

web: bundle exec passenger start --no-friendly-error-pages -p $PORT --max-pool-size $PASSENGER_MAX_POOL_SIZE

This is what happens:

$ foreman start
12:29:57 web.1  | started with pid 4810
12:29:57 web.1  | =============== Phusion Passenger Standalone web server started ===============
12:29:57 web.1  | PID file: /Users/Csuhta/Projects/test/tmp/pids/passenger.8080.pid
12:29:57 web.1  | Log file: /Users/Csuhta/Projects/test/log/passenger.8080.log
12:29:57 web.1  | Environment: development
12:29:57 web.1  | Accessible via: http://0.0.0.0:8080/
12:29:57 web.1  | You can stop Phusion Passenger Standalone by pressing Ctrl-C.
12:29:57 web.1  | ===============================================================================
12:30:00 web.1  | [ 2013-09-07 12:30:00.3584 4837/0x1072f6000 Pool2/Spawner.h:738 ]: [App 4849 stdout]
...
^CSIGINT received
12:30:04 system | sending SIGTERM to all processes
SIGTERM received
12:30:04 web.1  | terminated by SIGTERM

$ foreman start
12:30:06 web.1  | started with pid 4947
12:30:06 web.1  | *** ERROR ***
12:30:06 web.1  | The address 0.0.0.0:8080 is already in use by another process, perhaps another
12:30:06 web.1  | Phusion Passenger Standalone instance.
12:30:06 web.1  | If you want to run this Phusion Passenger Standalone instance on another port,
12:30:06 web.1  | use the -p option, like this:
12:30:06 web.1  |   passenger start -p 8081
12:30:06 web.1  | exited with code 1
12:30:06 system | sending SIGTERM to all processes
SIGTERM received

There are two nginx processes still running after foreman exits that that I have to reap manually with Activity Monitor.app or kill.

I'm on OS X 10.8.4.

@FooBarWidget
Copy link
Member

This is a problem, but not really a bug. Phusion Passenger responds correctly to SIGTERM and shuts down Nginx correctly. Foreman sends SIGTERM to Phusion Passenger correctly. The problem is that when pressing Ctrl-C in the terminal, SIGINT is sent by the operating system to all processes in the same terminal session. So when you press Ctrl-C, SIGINT is sent to Foreman and Phusion Passenger simultaneously. Phusion Passenger proceeds to stop Nginx. Foreman also attempts to stop Phusion Passenger by sending it SIGTERM, but it interrupts the Nginx stopping code instead, and so Nginx is never stopped.

I'll have a look at making the Nginx stopping section of the code less interruptable. In the mean time, you can work around this problem by stopping Foreman by sending it a SIGTERM signal with kill, instead of pressing Ctrl-C.

@amejiarosario
Copy link

👍

@FooBarWidget
Copy link
Member

Fixed in commit b749690 of in Phusion Passenger.

@amejiarosario
Copy link

I installed from source gem 'passenger', git: 'git://github.com/phusion/passenger.git' and it now works with foreman perfectly! Thanks @FooBarWidget!

@entaq
Copy link

entaq commented Jan 14, 2015

I know this issue is a bit old but we are seeing a daily R12 (exit timeout) errors from Heroku. Seems like Passenger doesn't correctly react to SIGTERM from Heroku when sent to the dynos?

https://devcenter.heroku.com/articles/dynos#graceful-shutdown-with-sigterm

@macowie
Copy link

macowie commented Mar 10, 2015

I'm also seeing 1-2 R12 errors daily on a few projects I switched over to Passenger on Heroku.

@FooBarWidget
Copy link
Member

Passenger responds fine to SIGTERM, but if during shutdown there are still active requests, it waits at most 30 seconds for the requests to finish. Heroku's shutdown timeout is only 10 seconds, and I don't know whether they abort requests before initiating shutdown.

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

5 participants