# lwIP: TCP connection reset by peer during SYN-SENT state, remote port 8080

- **ID:** `embedded/lwip-tcp-connection-reset-during-handshake`
- **Domain:** embedded
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

Remote host sends RST packet during TCP handshake due to firewall rules, port closed, or mismatched TCP window scale options.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| lwIP 2.1.3 | active | — | — |
| FreeRTOS+TCP 2.0.0 | active | — | — |
| ESP-IDF 5.1.2 | active | — | — |

## Workarounds

1. **Verify remote port is open using a separate tool (e.g., telnet or nmap from host PC). If port is closed, reconfigure server or firewall rules. For embedded device, add retry logic with exponential backoff in application code.** (85% success)
   ```
   Verify remote port is open using a separate tool (e.g., telnet or nmap from host PC). If port is closed, reconfigure server or firewall rules. For embedded device, add retry logic with exponential backoff in application code.
   ```
2. **Enable lwIP debug output for TCP events: set LWIP_DBG_ON in lwipopts.h and call tcp_debug_print(TCP_EVENT_CONNECT) to capture RST packet details, then adjust TCP_MSS or TCP_SND_BUF to match server expectations.** (70% success)
   ```
   Enable lwIP debug output for TCP events: set LWIP_DBG_ON in lwipopts.h and call tcp_debug_print(TCP_EVENT_CONNECT) to capture RST packet details, then adjust TCP_MSS or TCP_SND_BUF to match server expectations.
   ```

## Dead Ends

- **Increase TCP SYN timeout in lwIPopts.h (e.g., TCP_SYNMAXRTX = 12)** — Timeout increase does not prevent RST; RST is sent by remote host immediately, not a local timeout issue. (90% fail)
- **Disable TCP window scaling by setting TCP_WND to small value** — Window scaling mismatch is rarely the cause; disabling it may degrade performance without fixing the RST. (75% fail)
