Skip to content

Conversation

@Fr3ya
Copy link

@Fr3ya Fr3ya commented Nov 21, 2025

When a TCP connection in eCONNECT_SYN state times out after exceeding the maximum retry count, the socket was incorrectly transitioning to eCLOSE_WAIT state instead of eCLOSED.

According to the standard TCP state machine (RFC 793):

  • eCONNECT_SYN is the state where a client has sent a SYN and is waiting for a SYN-ACK
  • When connection establishment fails (timeout or RST), the socket should transition to eCLOSED state

This fix:

  1. Changes the state transition in prvTCPSendPacket() from eCLOSE_WAIT to eCLOSED when SYN retries are exhausted
  2. Updates vTCPStateChange() to handle the eCONNECT_SYN -> eCLOSED transition, ensuring connection state change callbacks are properly triggered.

This also aligns the timeout behavior with the existing RST handling code, which correctly uses eCLOSED state (see FreeRTOS_TCP_IP.c:859).

Files changed:

  • source/FreeRTOS_TCP_Transmission.c: Fix state transition
  • source/FreeRTOS_TCP_IP.c: Update vTCPStateChange to handle eCLOSED transition from connecting states

Description

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

When a TCP connection in eCONNECT_SYN state times out after exceeding the maximum retry count, the socket was incorrectly transitioning to eCLOSE_WAIT state instead of eCLOSED.

According to the standard TCP state machine (RFC 793):
- eCONNECT_SYN is the state where a client has sent a SYN and is waiting for a SYN-ACK
- When connection establishment fails (timeout or RST), the socket should transition to eCLOSED state

This fix:
1. Changes the state transition in prvTCPSendPacket() from eCLOSE_WAIT to eCLOSED when SYN retries are exhausted
2. Updates vTCPStateChange() to handle the eCONNECT_SYN -> eCLOSED transition, ensuring connection state change callbacks are properly triggered.

This also aligns the timeout behavior with the existing RST handling code, which correctly uses eCLOSED state (see FreeRTOS_TCP_IP.c:859).

Files changed:
- source/FreeRTOS_TCP_Transmission.c: Fix state transition
- source/FreeRTOS_TCP_IP.c: Update vTCPStateChange to handle eCLOSED transition from connecting states
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant