embedded network_error ai_generated true

lwIP: TCP retransmission timeout on connection 192.168.1.100:80, max retries exceeded

ID: embedded/lwip-tcp-retransmission-timeout

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
1Evidence
2023-07-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
lwIP V2.1.3 active — — —
FreeRTOS V10.4.3 active — — —

Root Cause

TCP connection lost due to network congestion, remote host unresponsive, or insufficient memory for retransmission buffers.

generic

中文

TCP 连接因网络拥塞、远程主机无响应或重传缓冲区内存不足而丢失。

Official Documentation

https://savannah.nongnu.org/projects/lwip/

Workarounds

  1. 85% success Increase lwIP memory pool for TCP segments: in lwipopts.h set `#define MEMP_NUM_TCP_SEG 64` and `#define TCP_SND_BUF 4096`.
    Increase lwIP memory pool for TCP segments: in lwipopts.h set `#define MEMP_NUM_TCP_SEG 64` and `#define TCP_SND_BUF 4096`.
  2. 80% success Implement application-level keep-alive with shorter interval (e.g., 5 seconds) to detect dead connections early.
    Implement application-level keep-alive with shorter interval (e.g., 5 seconds) to detect dead connections early.
  3. 90% success Use lwIP callback `tcp_err()` to handle connection reset and trigger reconnection logic.
    Use lwIP callback `tcp_err()` to handle connection reset and trigger reconnection logic.

中文步骤

  1. 增加 lwIP 的 TCP 段内存池:在 lwipopts.h 中设置 `#define MEMP_NUM_TCP_SEG 64` 和 `#define TCP_SND_BUF 4096`。
  2. 实现应用层保活机制,使用更短间隔(例如 5 秒)以尽早检测死连接。
  3. 使用 lwIP 回调 `tcp_err()` 处理连接重置并触发重连逻辑。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Increasing TCP timeout values delays failure but does not fix connectivity issue.

  2. 60% fail

    Disabling Nagle algorithm reduces latency but not retransmission due to packet loss.