Repository navigation
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The TCP state machine incorrectly transitions from eCONNECT_SYN (SYN-SENT) to eCLOSE_WAIT in error scenarios. Per RFC 793, connections that fail during establishment should transition to eCLOSED, not eCLOSE_WAIT.
FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Transmission.c
Lines 115 to 139 in 22c095e
| if( pxSocket->u.xTCP.eTCPState != eCONNECT_SYN ) | |
| { | |
| /* The connection is in a state other than SYN. */ | |
| pxNetworkBuffer = NULL; | |
| /* prvTCPSendRepeated() will only create a network buffer if necessary, | |
| * i.e. when data must be sent to the peer. */ | |
| lResult = prvTCPSendRepeated( pxSocket, &pxNetworkBuffer ); | |
| if( pxNetworkBuffer != NULL ) | |
| { | |
| vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); | |
| } | |
| } | |
| else | |
| { | |
| if( pxSocket->u.xTCP.ucRepCount >= 3U ) | |
| { | |
| /* The connection is in the SYN status. The packet will be repeated | |
| * to most 3 times. When there is no response, the socket get the | |
| * status 'eCLOSE_WAIT'. */ | |
| FreeRTOS_debug_printf( ( "Connect: giving up %xip:%u\n", | |
| ( unsigned ) pxSocket->u.xTCP.xRemoteIP.ulIP_IPv4, /* IP address of remote machine. */ | |
| pxSocket->u.xTCP.usRemotePort ) ); /* Port on remote machine. */ | |
| vTCPStateChange( pxSocket, eCLOSE_WAIT ); |
RFC 793 Compliance Issue
RFC 793 specifies that SYN-SENT state errors/timeouts should transition to CLOSED, not CLOSE-WAIT.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
jasonpcarroll commentedon Nov 20, 2025
HI @Fr3ya,
I agree with your assessment. Would you like to open a PR to resolve this?
Best,
Jason Carroll
htibosch commentedon Nov 20, 2025
You're quick, Jason. I'm still studying the effects of the change and simulate it on a LAN.
So please hold on a second.
Thanks, Hein
jasonpcarroll commentedon Nov 20, 2025
To be honest, I just looked at the code path and it appears to go from SYN to CLOSED_WAIT, which is against RFC 793 (figure 6 under 3.2 shows the state machine) as @Fr3ya pointed out.
htibosch commentedon Nov 21, 2025
I tested the proposed change in hardware: I could not find any different behaviour.
Do you want to create a PR your self? If not, we can do it as well.
I guess this is the only change FreeRTOS_TCP_Transmission.c:
Thank you
Fr3ya commentedon Nov 21, 2025
Thanks @htibosch @jasonpcarroll for heading up, I just opened the PR.