1

I am using Apache as a reverse proxy, and mod_rewrite to pass on the requests to backend services for handling.

I want to use Apache graceful stop, to allow in-flight requests to complete, however, it doesn't wait for rewritten requests to complete before terminating. Is this expected? (does Apache consider the request handled once rewritten?) if so, is there any other way of waiting for these requests to completed before shutting down?

I have tested as follows, first I have a basic loop curl-ing my service:

for (( i=1; i <= 200; ++i )); do curl -s -o /dev/null -w "%{http_code}" https://example.com/api?request=$i | sed "s/^/\n${i} /"; done;

I attach the request index to the URL so I can track the requests throughout, I then shutdown apache using the WINCH signal (I can see it logging that the correct signal is received, so happy that is sent ok)

What I then see, for example, is when it shuts down, the curl loop outputs:

97 200
98 502

If I then look at the logs for Apache, the last logged request matches this - the last logged request in Apache is request 97 returning a 200 OK (then I see the shutdown logging message). However, if I go to the backend service I can see in the logs that request 98 made it through, and the underlying service returned a 200 response, but that never makes it back to my curl client as they get a 502.

I have tried using both RewriteRule and ProxyPass (the proxy is working fine with that config, just not the graceful element)

RewriteRule ^/api/(.*) @backend_service@api/$1 

or

ProxyPass /api/ @backend_service@api/

(the backend_service is just a tokenised value, gets inserted later - but its all working there)

Any ideas how I can ensure that these proxied requests are completed before graceful shutdwon?

rhinds
  • 111
  • 3

0 Answers0