lwip-users
[Top][All Lists]
Advanced

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

Re: RE : [lwip-users] local connection failed on loopif, race?


From: Tai-hwa Liang
Subject: Re: RE : [lwip-users] local connection failed on loopif, race?
Date: Fri, 30 Mar 2007 09:22:37 +0800 (CST)

On Mon, 26 Mar 2007, Fr嶮廨ic BERNON wrote:
The workaround you have find is "something like" the one I proposed in 
https://savannah.nongnu.org/bugs/?19157 ("lwip_close problems"). It would be good to add 
a netconn_close in your code. Follow information for bug #19157 : lwip_close problems, I will 
propose a patch, like (not yet tested like this) :

err_t
netconn_close(struct netconn *conn)
{
 struct api_msg msg;

 if (conn == NULL) {
   return ERR_VAL;
 }

 conn->state = NETCONN_CLOSE;
again:
 msg.type = API_MSG_CLOSE;
 msg.msg.conn = conn;
 api_msg_post(&msg);
 if (conn->err == ERR_MEM && conn->sem != SYS_SEM_NULL) {
   sys_sem_wait(conn->sem);
   goto again;
 }
 if (conn->type==NETCONN_TCP) {
   if (((sock->conn->pcb.tcp->unacked!=NULL) || (sock->conn->pcb.tcp->unsent!=NULL)) 
&& (sock->conn->err==ERR_OK)) {
     sys_msleep(1);//I don't like that, but...
     goto again:
 }
 conn->state = NETCONN_NONE;
 return conn->err;
}

Hi Fr嶮廨ic,

  With your patch, my testing code never hangs(complete millions of
client/server transactions).  It is interesting to note that with a
"sys_msleep(1)" inside the patch, the performance is much better than the
patch without one.  I guess that's probably because the sys_msleep() gives
another thread a chance to run, which is crucial in my testing case.

  On the other hand, for certain low memory constraint, say, MEM_SIZE=1024,
my test usually crashed into a NULL conn->pcb, which requires another
(conn->pcb.tcp != NULL) workaround:

      if ((conn->pcb.tcp != NULL) && ((conn->pcb.tcp->unacked != NULL) ||
        (conn->pcb.tcp->unsent != NULL)) && (conn->err == ERR_OK)) {
        sys_msleep(1);
        goto again;
      }

  However, this workaround does not solve the hanging problem I've mentioned
about in my first post.  It turns out that raising MEM_SIZE to 2048 is the
only 'solution' at this moment.

-----Message d'origine-----
De : address@hidden [mailto:address@hidden De la part de Tai-hwa Liang
Envoy� : lundi 26 mars 2007 08:28
� : Mailing list for lwIP users
Objet : Re: [lwip-users] local connection failed on loopif, race?


On Mon, 19 Mar 2007, Tai-hwa Liang wrote:
Hi,

 Is there anyone having success on using loopif in a multi-threaded
application?  The attached is a modified unix/proj/unixsim/simhost.c.
Basically it is a self-contained server/client which binds/connects to
127.0.0.2 through loopif.

 The problem is that this program failed to run indefinitely and hung
after a few client <-> server transactions(lwIP CVS version, with
LWIP_HAVE_LOOPIF = 1, running on FreeBSD-CURRENT):

freebsd> ./simhost -d
Host at 127.0.0.2 mask 255.0.0.0 gateway 127.0.0.1
System initialized.
TCP/IP initialized.
netif_set_ipaddr: netif address being changed
netif: IP address of interface API message 0x8065a28
cli connecting...
[...]
tcp_output: snd_wnd 8096, cwnd 2048, wnd 2048, seg == NULL, ack 6539
State: FIN_WAIT_1
srv listening return, proceed to accept
[...hanging...]

  I managed to workaround this hanging by adding a 1 second delay between
netconn_write() and netconn_delete():

        /* pseudo code */
        for (;;) {
                srv = netconn_new(NETCONN_TCP)
                netconn_connect(srv, srv_addr, srv_port);
                netconn_write(srv, buf, len, NETCONN_NOCOPY);
                sleep(1);       /* this is vital! */
                netconn_delete(srv);
        }

  In addition to that, the default setting of MEMP_NUM_SYS_TIMEOUT in unixsim still isn't 
able to cope with the load required in my loopif testing case.  Raising the default value 
from 3 to 8 plus the aforementioned 1 second delay seems to "resolve" the 
hanging observed in my case.

  Now the question turns to be: why armed sys_timeout() inside lwIP seems to 
"lost" when the system is heavily stressed?

--
Thanks,

Tai-hwa Liang

reply via email to

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