tcp: mitigate illegal state transitions on simultaneous close #279
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.
If a socket is closed and the remote side sends a FIN before the local
side sends its own FIN, it is possible to jump directly from FIN-WAIT-1
to CLOSING without ever sending a FIN to the remote side.
The main side effect is that if untransmitted data is present, the
socket is never exhausted, causing
EthernetInterface::poll
to loopforever.
The ideal fix is to follow RFC more closely and not transition to
FIN-WAIT-1 until the FIN has been sent, but there are too many
assumptions based on the current state that would be broken by remaining
in ESTABLISHED with a closed transmit buffer to be worth fixing
a relatively rare edge case. Instead, add another illegal transition to
fix the failures of a previous violation, in the spirit of all good TCP
stacks.
The main reason why this is a problem at all is because
poll
performs ingress before egress, which is how this possibility can even arise. I haven't thought too hard about the implications of swapping them around. Maybe because, as already stated, this is a pretty rare occurrence to begin with.