lwip tcp_tw_pcbs list problem in tcp_slowtmr()

转载 2015年07月10日 14:18:05
lwip tcp_tw_pcbs list problem in tcp_slowtmr()

I have been having a problem in the tcp_slowtmr() function in tcp.c.  I have been using the raw api for a quite a while to implement TCP servers listening on several different ports.  I have not really had any problems so far.  Recently I have also implemented TCP client connection which quickly open up a TCP client connection read/write some data and then close the connection.  This sequence repeats itself over and over connecting to several different remote TCP servers.  Things seem to work fairly well until I start introducing some error conditions like extending remote server resonse times or reducing my timeouts waiting for data to be received.  This causes my code to timeout and close the TCP connection (probably while some responses may come back in later).  I have also tried disconnecting some of my remote servers network connections so that the initial client connection attempts will fail.  I am just mainly trying to do some general stress testing with normal conditions that may occur when deploying the application.

The problem that I am having occurs when adding these additional stress tests, and possibly with normal conditions after an extended period of time.  I have not nailed down the exact cause as of yet.  I finally get into a lock up condition when calling the tcp_slowtmr() function.  The lockup occurs cycling through the code lines highlighted below from the tcp_slowtmr() function:

  /* Steps through all of the TIME-WAIT PCBs. */

prev = NULL;

  pcb = tcp_tw_pcbs;

  while (pcb != NULL) {

    LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);

    pcb_remove = 0;

    /* Check if this PCB has stayed long enough in TIME-WAIT */

    if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {




    /* If the PCB should be removed, do it. */

    if (pcb_remove) {

      struct tcp_pcb *pcb2;


      /* Remove PCB from tcp_tw_pcbs list. */

      if (prev != NULL) {

        LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);

        prev->next = pcb->next;

      } else {

        /* This PCB was the first. */

        LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb);

        tcp_tw_pcbs = pcb->next;


      pcb2 = pcb;

      pcb = pcb->next;

      memp_free(MEMP_TCP_PCB, pcb2);

    } else {

      prev = pcb;

      pcb = pcb->next;



The problem occurs when the first item on the tcp_tw_pcbs list points back to itself:  pcb->next == pcb, so the code never exits the while loop.  The tcp_ticks value never changes in this part of the code so pcb_remove is never set > 0 either.

This is a single threaded application and only the standard interrupt handling function are being used.  This is an application running on an LPC4350 using the LPCOpen library from NXP with lwip v1.4.1.

It seems like the problem is created if I start calling tcp_close() to close my client connections.  If I use tcp_abort() instead then I don’t seem to have to problem – It does however cause undesirable sequences in wireshark.

What is the recommended sequence to close a tcp client session using the raw api?

Any suggestions as to what I may be doing wrong here or could this possibly be a bug that has been seen before in lwip?

Greg Dunn


  • sealyao
  • sealyao
  • 2010年08月25日 21:04
  • 9816

LwIP协议栈源码详解——TCP/IP协议的实现 TCP定时器

  • zsk42142269
  • zsk42142269
  • 2012年11月07日 15:24
  • 955


  • yusiguyuan
  • yusiguyuan
  • 2014年10月14日 11:42
  • 1723

TCP 慢启动(slow start)报文观察

慢启动定义 慢启动,是传输控制协议使用的一种拥塞控制机制。慢启动也叫做指数增长期。慢启动是指每次TCP接收窗口收到确认时都会增长。增加的大小就是已确认段的数目。这种情况一直保持到要么没有收到一些段,...
  • abccheng
  • abccheng
  • 2016年01月12日 16:08
  • 1712

Linux两种方法来处理传入TCP数据段:快速路径(Fast Path)和慢速路径(Slow Path)

在Linux中,有两种方法来处理传入TCP数据段:快速路径(Fast Path)和慢速路径(Slow Path)。使用快速路径只进行最少的处理,如处理数据段、发生ACK、存储时间戳等。使用慢速路径可以...
  • zhou1021jian
  • zhou1021jian
  • 2017年04月07日 18:14
  • 641


TCP定义了几个拥塞事件,当这些事件发生时,我们可以通过TCP的拥塞控制算法,调用自定义的处理函数, 来做一些额外的事情的。也就是说,我们可以很简便的参与到TCP对拥塞事件的处理过程中。...
  • zhangskd
  • zhangskd
  • 2013年10月09日 10:40
  • 3826

Hybrid Start(混合慢启动)

Standard slow start does not work well under large bandwidth-delay product (BDP) networks. We find t...
  • already_skb
  • already_skb
  • 2015年02月11日 13:29
  • 786


 1.怎样找到我想安装的包路径: # cd /usr/ports # make search name=mysql 2.仅仅下载源码包,而不安装: # cd /usr/ports/dir...
  • willhuo
  • willhuo
  • 2015年10月24日 12:42
  • 1202

Tcp性能调优 解决Tcp长延时

Tcp 长延时 Tcp 长尾 Tcp 调优
  • Happyqunqunqun
  • Happyqunqunqun
  • 2016年04月06日 23:11
  • 9887


慢查询分析步骤: 1,登录mysql,查看慢查询参数状态: show variables where Variable_name in ("slow_query_log","slow_query_lo...
  • huoyuanshen
  • huoyuanshen
  • 2017年04月12日 14:34
  • 413
您举报文章:lwip tcp_tw_pcbs list problem in tcp_slowtmr()