Close a TCP connection when indicated by Connection: Close header. #447
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.
Introduction
Close the TCP connection when indicated by
Connection: close
header in the received response.Background
So far, Styx has ignored the received
Connection: close
header, and relied on sender to close the TCP connection, and on Netty to deliver achannelInactive
event. This behaviour introduces a race condition that subtly increases failed requests manifesting in Styx 502 responses.This behaviour unnecessarily delays the connection removal, and is a problematic specifically with pooled connections. A pooled connection may be reused for another request wile the operating system and/or TCP protocol is processing connection closure (transmitting FIN). When a request is sent on such a connection, it will be rejected by the remote peer, resulting in a TCP reset.
Solution
Check if the
Connection: close
header is present in a response. If so, close the connection straight away. This taints the connection so that it won't be used for any future requests, eliminating the race condition.