[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #57710] Unable to reinitialize the TCP connection

From: Benjamin K
Subject: [lwip-devel] [bug #57710] Unable to reinitialize the TCP connection
Date: Mon, 3 Feb 2020 02:09:38 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

Follow-up Comment #1, bug #57710 (project lwip):

I had a similar problem for a long time, and I think I have fixed it now. In
my case the reason was insufficient resources, but my MCU was not going to
sleep, but the connection was interrupted because the WLAN device lost it's
connection. I had a web server running on my system that was processing many
asynchronous requests from a client. Once the connection became unstable and
was about to be terminated, some TCP/IP responses could no longer be sent to
the client. As a result, the PCBs from the pool were used up very quickly. But
since the connection was never explicitly closed, they were never released.
Because of that, I was forced to activate TCP_KEEPALIVE. For this purpose I
have included in the file lwipopts.h 

#define LWIP_TCP_KEEPALIVE              1
#define TCP_KEEPIDLE_DEFAULT                    5000
#define TCP_KEEPINTVL_DEFAULT                   5000

#define LWIP_NETCONN_FULLDUPLEX                 1

This ensures that any TCP/IP connection that may have been closed on the
client side or is not answered by the client any more, will be closed after 5
seconds of inactivity. This frees up all internal resources. In my case, the
problem that took me weeks to solve was solved immediately.

Please note, keep alive feature has to be explicitly activated per TCP/IP
connection. If you are using sockets API this could be like so:

int ClientSocket = lwip_accept(ServerSocket, (struct sockaddr *) &ClientInfo,
&AddrLen); // Blocking
if (ClientSocket > 0) {
        int ParamOpt = 1;
        lwip_setsockopt(ClientSocket, SOL_SOCKET, SO_KEEPALIVE, &ParamOpt,

This is worth a try in your case.


Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]