From 223101f1ed110804e3526f3afc5da465240ea87c Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 29 Dec 2020 21:35:25 +0100 Subject: [PATCH] tcp_in: Flag the pcb as closing if TCP_EVENT_CLOSED refused If the packet contained FIN flag, we post a TCP_EVENT_CLOSE with null pbuf, which could get lost if the underlying platform implementation of sys_mbox_(try)post() returns ERR_MEM (i.e. won't fit into the recv mailbox). Loosing this event causes trouble since the FIN initiator gets ACK'ed and assumes the connection has closed, but the TCP state machine is stuck in its active state. Fixed by flagging the pcb as closing if the ERR_MEM returned. Picked from espressif/esp-lwip@d050c331 Patch posted https://savannah.nongnu.org/patch/?10013 Ref IDF-4847 --- src/core/tcp_in.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index e016b94f..b0892f64 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -541,6 +541,8 @@ tcp_input(struct pbuf *p, struct netif *inp) TCP_EVENT_CLOSED(pcb, err); if (err == ERR_ABRT) { goto aborted; + } else if (err == ERR_MEM) { + tcp_set_flags(pcb, TF_CLOSEPEND); } } }