The scenario is as below:
- There is an http reverse proxy, that has a pool of persistent connections with the application server. It has received a request from client and makes the same request to backend after checking that the connection is open
- Meanwhile, the server closes the connection before receiving the request, and the proxy fails with error reading from backend.
- An error is sent to the client.
How should this race condition be handled:
- All connection close should be initiated by proxy and never by the backend server?
- Proxy should retry request when it fails to send because of connection close?
Proxy just passes through the traffic. If the server has closed the connection, proxy should also immediately close it, even if there is a request pending.
However, from the client site the described situation looks like server hasn't returned any data for the request. This should be prevented by 'keep-alive' handshake.
In HTTP protocol the header "Connection:" is used for such case. Client includes "Connection: Keep-Alive" if he wants to keep the TCP session open after the request will be processed (so it will be possible to send the next HTTP request within the same TCP session). Server still may reply with "Connection: Close" header, which means TCP session will be closed anyways.