heroku / heroku-buildpack-nginx

Run NGINX in a Heroku app
1 stars 3 forks source link

fix: sigterm handling so NGINX gracefully exist #65

Closed sbdchd closed 4 years ago

sbdchd commented 4 years ago

After compiling nginx with the modifications:

make build-heroku-18

I tested that the changes actually worked:

apt-get update
apt-get install -y python3-venv
python3 -m venv venv
./venv/bin/pip install gunicorn
FORCE=1 bin/start-nginx
./venv/bin/gunicorn -b unix:/tmp/nginx.socket app:app

# in another terminal (should hang for 15s assuming app is setup correctly)
curl localhost:5000

# in another terminal
# get the PID
ps aux | grep master

# should be graceful, that is nginx should shutdown after it finishes serving the request
kill -TERM $PID

FORCE=1 bin/start-nginx
# should kill nginx without waiting
# curl returns an error:
#   curl: (52) Empty reply from server
kill -QUIT $PID

The app used by gunicorn was the hello world with a sleep thrown in so we mimic a long running request.

import time

def app(environ, start_response):
        time.sleep(15)
        data = b"Hello, World!\n"
        start_response("200 OK", [
            ("Content-Type", "text/plain"),
            ("Content-Length", str(len(data)))
        ])
        return iter([data])

Based on https://github.com/heroku/heroku-buildpack-nginx/pull/56 https://admithubteam.atlassian.net/browse/AH-4919

sbdchd commented 4 years ago

Whoops! meant to do this on the fork