[Top][All Lists]

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

Re: [lwip-users] TCP break down with concurrent client accept

From: Oldrich Kepka
Subject: Re: [lwip-users] TCP break down with concurrent client accept
Date: Fri, 7 Sep 2018 23:59:36 +0000

Hi again,

I found that the reason for tcp networking to break is that there are no available semaphores to initialize. We run out of semaphores, because some connection don't close. They don't close because they are stuck in read function.
while(1) {
   n = read(s, ...)
   if(n<=0) break;

More concretely in sys_arch_mbox_fetch in netconn_recv_data. The loop above goes through once and data ara read. However, the thread gets stuck during the second pass through in read.

Checking the pcbs looped in tcp_slowtmr, I found out that the stuck connections have a state CLOSE_WAIT. So the application should normally call close(s), but do to some race condition, we are stuck in read, and cannot do that.

Thanks for any help,

On Tue, 4 Sep 2018 at 08:33, Oldrich Kepka <address@hidden> wrote:
Hi Simon,

I return to this old post. As you requested, I migrated our system to 2.0.2 using Xilinx port of LWIP.

and I observe the same behaviour that I reported above.

I am able to reproduce the break with SOCKETS_DEBUG=1. This shows:
17:24:27.846: lwip_accept(2)...                                                                                    
17:24:27.848: lwip_accept(2): netconn_acept failed, err=-13

I have not yet been able to break it with also TCPIP_DEBUG=1. There is a sort of race condition which is not met when printing out more info.

Attached find lwipopts.h and sys_arch.c which might be useful.

Thanks for any hint where to look or how to get more debug information.


On Sat, 31 Mar 2018 at 23:26, Oldrich Kepka <address@hidden> wrote:

we run lwip-1.4.0 on PPC440 and experience rare random hanging of TCP. I was able to create a minimal working example to reproduce the hang: Setup a tcp server on the PPC:

    int socketId =  socket(AF_INET, SOCK_STREAM, 0);
    if(socketId == -1){...return;}

    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_port = htons(12121);
    server.sin_addr.s_addr = INADDR_ANY;

    int err = bind(socketId, (struct sockaddr *) &server, sizeof (server));
    if (err < 0) {... return;}
    err = listen(socketId, 1);
    if (err < 0) { .... return;}

   while(1) {

        int socketConn = accept(socketId, NULL, NULL);
        sys_thread_t thread = sys_thread_new("tcip_server", processConnection,

sponing a thread on accepted connection:

void processConnection(void *p) {

    int sd = (int)p;
    uint8_t *buffer = new uint8_t[CMD_MAX_SIZE];
    uint32_t n = 0, bufOffset = 0;

    while((n  = read(sd, buffer+bufOffset, CMD_MAX_SIZE-bufOffset)) > 0 ) {
        bufOffset += n;
    if(buffer) delete buffer;


Then keep dumping the content of a file (~30 characters)
for i in {1..n}; do cat some_file > /dev/tcp/DEVICE_IP/12121; done
from 2 shells at the same time. For some time I see random

cat: write error: Connection reset by peer

However after some time, this message is printed after every command of any of the two threads. At this point the tcp breaks. I admit that this example is rather agressive, but allows me to get the system to a similar problematic state that we experience in production.

I found that after the TCP breaks down, UDP communication still works and I am able to check the state of the system. For example, lwip_stats.tcp counts properly incoming TCP packets. One cannot however create new tcp socket anymore. I don't see TCPIP_MSG_API messages in tcpip_thread anymore, etc. Placing printouts/usleep(1000) inside in some places removes the (race condition) problem, but also slows the system.

Any advice on how to move forward in debugging this would be very much appreciated. opt.h and tcp_impl.h attached. I tried to play blindly with a few paramters (TCP_TMR_INTERVAL, TCP_SLOW_INTERVAL, MEM_ALIGNMENT, MEMP_OVERFLOW_CHECK, MEMP_NUM_TCP_PCB, MEMP_NUM_TCP_PCB_LISTEN) with no success.


reply via email to

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