Repository navigation
Hold writes until the SYN-ACK has been sent - #106
Open
FrenchToblerone54 wants to merge 1 commit into
Open
FrenchToblerone54 wants to merge 1 commit into
FrenchToblerone54 wants to merge 1 commit into
Conversation
A write made before the task that answers the SYN has run was sent under the initial sequence number, ahead of the SYN-ACK, which the peer does not accept. Keep poll_write pending while the session is still in Listen and wake it once the SYN-ACK is on its way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The SYN-ACK is sent by the session's task, which may not have run when the caller gets the stream. A write made in that window goes out through
poll_writeunder the initial sequence number, ahead of the SYN-ACK. The peer does not accept data before the handshake, so the connection stalls or is reset. It is more likely on a current-thread runtime, or when the accepting task writes right afteraccept()returns.Reproduce
Create a stream from a SYN and call
poll_writebefore yielding to the runtime. The write is accepted and its packet reaches the device before the SYN-ACK. The new test checks the order of the packets.Fix
poll_writeregisters its waker onwrite_notifyand returnsPendingwhile the session is still inListen.write_notifyright after it has sent the SYN-ACK and moved toSynReceived.Once the SYN-ACK is out, writes behave as before.
Test
write_before_the_syn_ack_waits_for_itinsrc/stream/tcp.rs. It fails without the change ("a write was accepted before the SYN-ACK went out") and passes with it; it also checks that the writer is woken and that the data follows the SYN-ACK.cargo testandcargo clippy --all-targetsare clean.