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

[WIP] Patch NGINX to allow it to better handle SIGTERM #56

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

chap
Copy link

@chap chap commented May 22, 2020

Not sure yet if this is going to work, but trying to address the problems raised in #31

@beanieboi
Copy link
Member

nice! :)

@jgminer
Copy link

jgminer commented May 26, 2020

I ran this locally but I was getting trouble having it log out on SIGTERM at all - with the Docker Hub vanilla NGINX container it logs out quite a bit of info in debug mode (with the error.log debug set and nginx-debug executable). Besides this issue, I don't have any reason to say this patch is/isn't working.

@jgminer
Copy link

jgminer commented May 26, 2020

Also, @chap it looks like the build will pass if we update the changelog, at least based on the comment on that part of the Github check.

@@ -41,6 +41,26 @@ echo "Downloading $zlib_url"
echo "Downloading $uuid4_url"
(cd nginx-${NGINX_VERSION} && curl -L $uuid4_url | tar xvz )

if [ -d "/buildpack/support/patchfiles/${NGINX_VERSION}" ]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ -d "/buildpack/support/patchfiles/${NGINX_VERSION}" ]
if [ -d "/buildpack/scripts/patchfiles/${NGINX_VERSION}" ]

sbdchd added a commit to AdmitHub/heroku-buildpack-nginx that referenced this pull request Oct 7, 2020
After compiling nginx with the modifications:

```shell
make build-heroku-18
```

I tested that the changes actually worked:

```shell
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.

```python
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 heroku#56
sbdchd added a commit to AdmitHub/heroku-buildpack-nginx that referenced this pull request Oct 8, 2020
After compiling nginx with the modifications:

```shell
make build-heroku-18
```

I then tested that the changes actually worked:

```shell
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.

```python
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 heroku#56
Base automatically changed from master to main January 18, 2021 12:16
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

Successfully merging this pull request may close these issues.

4 participants