# lwIP：TCP 连接在 SYN-SENT 状态下被对端重置，远程端口 8080

- **ID:** `embedded/lwip-tcp-connection-reset-during-handshake`
- **领域:** embedded
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

远程主机在 TCP 握手期间发送 RST 包，原因包括防火墙规则、端口关闭或 TCP 窗口缩放选项不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| lwIP 2.1.3 | active | — | — |
| FreeRTOS+TCP 2.0.0 | active | — | — |
| ESP-IDF 5.1.2 | active | — | — |

## 解决方案

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.
   ```
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.
   ```

## 无效尝试

- **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% 失败率)
- **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% 失败率)
