Skip to content

[BUG] State Transition from eCONNECT_SYN to eCLOSE_WAIT? #1301

Open

Description

@Fr3ya

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.

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.

Activity

  1. jasonpcarroll commented on Nov 20, 2025

    @jasonpcarroll
    Contributor

    HI @Fr3ya,

    I agree with your assessment. Would you like to open a PR to resolve this?

    Best,

    Jason Carroll

  2. htibosch commented on Nov 20, 2025

    @htibosch
    Contributor

    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

  3. jasonpcarroll commented on Nov 20, 2025

    @jasonpcarroll
    Contributor

    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.

  4. htibosch commented on Nov 21, 2025

    @htibosch
    Contributor

    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:

    -    vTCPStateChange( pxSocket, eCLOSE_WAIT );
    +    vTCPStateChange( pxSocket, eCLOSED );

    Thank you

  5. Fr3ya commented on Nov 21, 2025

    @Fr3ya
    Author

    Thanks @htibosch @jasonpcarroll for heading up, I just opened the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions