[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [lwip-users] netconn_delete and _recv not thread safe
From: |
Krueger, Don |
Subject: |
RE: [lwip-users] netconn_delete and _recv not thread safe |
Date: |
Fri, 15 Dec 2006 10:05:40 -0500 |
> I have most of the lwip stack running in a "tcpip" thread, and stack
> users in various threads synchronise with it using the netconn* API.
But
> there is a problem with netconn_delete and netconn_recv when they
delete
> mboxes. A packet, or a connection to a listening socket, may arrive in
> the gap between removing mbox items, and deleting the mboxes. For
> example:
>
> /* Drain the recvmbox. */
> if (conn->recvmbox != SYS_MBOX_NULL) {
> while (sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) !=
SYS_ARCH_TIMEOUT) {
> if (conn->type == NETCONN_TCP) {
> if(mem != NULL)
> pbuf_free((struct pbuf *)mem);
> } else {
> netbuf_delete((struct netbuf *)mem);
> }
> }
>
> *** PACKET CAN ARRIVE HERE ***
> sys_mbox_free(conn->recvmbox);
> conn->recvmbox = SYS_MBOX_NULL;
> }
>
> In that case a sys_mbox_free can be called on a non-empty mbox. This
may
> either leak a pbuf, or cause an assertion in the OS from the
underlying
> mbox implementation. I've been thinking about how to fix this. Either
> new sys_arch primitives could be added. Or, better, we could try to
use
> SYS_LIGHTWEIGHT_PROT, but this seems a bit dubious as we need to
protect
> from before the sys_arch_mbox_fetch, until the conn->recvmbox =
> SYS_MBOX_NULL.
Doesn't the API_MSG_DELCONN message posted just prior to the above code
already prevent any further packets from being placed in the recvmbox?
Don Krueger
======================================================================
This electronic message transmission and any attachments are
confidential and/or proprietary and may constitute legally privileged
information of
Meso Scale Diagnostics, LLC. The information is intended for solely
the use of Mailing list for lwIP users (address@hidden). If you are not
the intended recipient, you are hereby notified that any
disclosure, copying, distribution or the taking of any action in
reliance of this information is strictly prohibited. You are not
authorized to retain it in any form nor to re-transmit it, and
you should destroy this email immediately.
If you have received this electronic transmission in error,
please notify us by telephone (240-631-2522) or by electronic
mail to the sender of this email, Krueger, Don (address@hidden),
immediately.
=====================================================================