I am trying to find a way to quickly restart Apache to apply configuration changes. The goal is to:
- Restart without distributing currently processed requests
- Do this as atomically as possible, i.e. the new configuration must be applied on all new requests received from the restart time on, no new requests should by handled by the old version.
Apache has a graceful restart command that satisfies the first goal, the restart command is immediate and existing requests are not affected. However, the restart is not atomic. If there are existing connections to the server in Keep-Alive state, then all the following requests that they send are handled by old processes with the old configuration.
In my case, the Apache server is sitting behind a load balancer which may send hundreds of requests over a single connection. So after the restart, it takes many long minutes until the new configuration is applied to all new requests.
Is there any way to fix this, e.g. make Apache close any existing Keep-Alive connection to an old process after it finishes serving the current request?