Repository navigation
Conversation
When the peer's FIN arrives while Tx data is still queued, prvHandleEstablished() refuses it, but since FreeRTOS#1195 it advances rx.ulCurrentSequenceNumber past the FIN, so the FIN is ACKed and the peer will not retransmit it. The FIN check only ran when bFinAccepted was set or the current segment carried FIN, so the refused FIN was never looked at again: once the Tx queue drained, the socket stayed ESTABLISHED, never sent its own FIN, and FreeRTOS_recv() never returned. Also enter the check when bFinRecv is set, so the refused FIN is re-evaluated on each later segment until Rx and Tx are complete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KSfhgGX3d6cx2tfP6Leo4S
This branch has not been deployed
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.
Description
When the peer's FIN arrives while the socket still has Tx data queued,
prvHandleEstablished()refuses it (the "Refusing FIN" path with
bTxDone == 0). Since #1195 it also advancesrx.ulCurrentSequenceNumberpast the FIN, so the FIN is ACKed and the peer will notretransmit it.
The FIN check, however, only runs when
bFinAcceptedis set or the current segment carriesFIN. The peer's later segments only ACK our remaining data, so the refused FIN is neverlooked at again. Once the Tx queue drains, the socket stays ESTABLISHED forever:
FreeRTOS_recv()never returns, so a task blocked in it waits indefinitely.This change also enters the check when
bFinRecvis set. A refused FIN is then re-evaluatedon each later segment, until Rx and Tx are complete and the normal closing flow
(
prvTCPHandleFin()) runs.Test Steps
Hardware, V4.4.2: NUCLEO-F767ZI (STM32F767ZI), STM32 network interface,
FreeRTOS-Kernel V11.1.0.
The board runs a TCP echo server:
accept, thenFreeRTOS_recv()/FreeRTOS_send()untilrecvreturns <= 0, then shutdown and close.A Linux PC sends 100,000 bytes and half-closes right away, so the PC's FIN arrives while
the echo is still being transmitted:
Results:
ss -tan). The echo task stays blocked inFreeRTOS_recv(), so the next two connections are never served.Unit tests: two new tests in
FreeRTOS_TCP_State_Handling_utest.c.test_prvHandleEstablished_FINRecvRefusedEarlierThenTXDone: an ACK without FIN, after arefused FIN, with Rx and Tx done, accepts the FIN and starts the closing flow.
test_prvHandleEstablished_FINRecvRefusedEarlierTXNotDone: the same while Tx data is stillpending refuses it again and only ACKs.
Both fail on the current
mainand pass with this change. The full unit-test suite passes:ctest -E system, 60/60.Checklist:
Related Issue
Follow-up to #1195 (which made the refused FIN ACKed). No separate issue filed.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.