1

I have an nginx web server to which I execute an nginx -s quit. This is supposed to be a graceful shutdown, so its supposed to wait for all its connections to finish before shutting down.

To test to make sure that it is doing as advertised, I execute a curl on a 10M file served by nginx with --rate-limit=1024K (per second), giving me 10 seconds to execute an nginx -s quit before the download finishes. I would expect nginx to finish the download and then shut down, but every time I do this in the beginning of the download, nginx quits anyway and curl says:

curl: (18) transfer closed with 2019456 bytes remaining to read

Why would nginx shut down anyway? I couldn't find any documentation that says "Nginx waits for all connections to complete except..." My only theory is that with a rate limit, curl waits for such a long time in between sending packets that nginx thinks that the connection is stale... or something.

What am I doing wrong or misunderstanding?

EDIT:

I have done the same test on my local machine and everything worked correctly, so this is no longer a question about nginx. The environment in which the signal does not work correctly is google's kubernetes container cluster manager, where nginx is running. The nginx -s quit is executed as a pre-stop hook, but it also fails when I exec into the docker container and run the quit command on the command line during the download. Note: my successful local machine test was done with nginx running inside a docker container, so it's NOT docker.

nckturner
  • 111
  • 5
  • Are you using the official nginx image? if `nginx -s quit` returns immediately and you image doesn't configure STOPGINAL, then the container will recevie SIGTERM immediately after the hook. – Tamir Daniely Feb 23 '22 at 09:46

1 Answers1

1

The only obvious thing I can think of is that nginx is PID 1 inside the container, but not on your desktop. There's nothing particular to kubernetes here - it's just plain Docker in this regard.

I tried to reproduce this, but it worked correctly for me. Here is the pod I used:

apiVersion: v1
kind: Pod 
metadata:
  namespace: demos
  name: pods-demo
  labels:
    demo: pods
spec:
  containers:
  - name: busybox
    image: busybox
    command:
    - sh
    - -c
    - dd if=/dev/zero of=/data/index.html bs=1024 count=10240; sleep 1000000
    volumeMounts:
    - name: content
      mountPath: /data
  - name: nginx
    image: nginx
    volumeMounts:
      - name: content
        mountPath: /usr/share/nginx/html
        readOnly: true
  volumes:
  - name: content
Tim Hockin
  • 282
  • 1
  • 6