Implement keep_alive_timeout option #14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's a well known race condition with http keep alive connections. If the server closes the connection after the client has checked the socket is still connected, but before it has prepared the request to send it, then the client will receive an EPIPE error and fail the entire request when it tries to write the request to the socket.
This means clients always have to check for this case and decide what to do, which could be resend the request depending on when exactly the EPIPE occured and whether the request was idempotent or not.
Another work around for this is to make sure the client has a keepalive reuse timeout that's less than the server keepalive time. So for instance if the client has a 5 second timeout and the server has a 10 second timeout, then if it's been > 5 seconds since the connection was last re-used, the client will close it and open a new one, avoiding the case where the server would close the connection on it.
This setup can be very useful when using HTTP::Tiny to send requests to internal service endpoints and wanting as much as possible to avoid this edge case failure more.