Repository navigation
Report end-of-stream to the reader once the peer's FIN is in - #104
Open
FrenchToblerone54 wants to merge 1 commit into
Open
FrenchToblerone54 wants to merge 1 commit into
FrenchToblerone54 wants to merge 1 commit into
Conversation
poll_read stayed pending after the peer closed its side, because nothing woke the reader and CloseWait, LastAck and TimeWait were not treated as end of stream. Wake the reader on a FIN and return end-of-stream when no more data can arrive.
FrenchToblerone54
force-pushed
the
tcp-eof-after-fin
branch
from
October 17, 2026 09:38
972a691 to
079d7aa
Compare
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
After the peer closes its side, a task blocked in
poll_readis never woken and the read stays pending until the idle timeout. Nothing in the FIN path wakes the reader, andCloseWait,LastAckandTimeWaitare not treated as end of stream when the data channel is empty. A relay that copies from the stream to another socket does not learn that the peer is done, so it holds the connection open for up to the session timeout.Reproduce
Open a connection, start a read that stays pending, then deliver an
ACK|FINfrom the peer at the expected sequence number. The reader is not woken. The new test does exactly this.Fix
poll_read, when the channel is empty and the state isCloseWait,LastAckorTimeWait, returnReady(Ok(()))with nothing read, which is end of stream. Data already queued is still delivered first: the channel is polled before the state is looked at, and acknowledged bytes that still wait in theTcbfor a free channel slot are taken from there (the sametake_receivedtheClosedbranch uses) before end of stream is reported.Test
reader_sees_end_of_stream_after_the_peers_fininsrc/stream/tcp.rs. It fails without the change ("the peer's FIN did not wake the pending reader") and passes with it.queued_data_is_read_before_end_of_streamuses a one-slot data channel, two data segments and then FIN, and reads without ever yielding in between; it asserts every byte arrives before end of stream and fails without thetake_receivedstep ("bytes were lost before end-of-stream").cargo testandcargo clippy --all-targetsare clean.