Skip to content

Commit 9e92724

Browse files
Fix race condition in WiFiServer
It is possible under heavy load with multithreading that a connection gets a tcp_abort just before tcp_accept will be called. When we abort, we clear the this pointer, and so when we try and recover our object we crash. Check for aborted connections (and ignore) on WiFiServer, like we do in WiFiClient
1 parent ef0ce09 commit 9e92724

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libraries/WiFi/src/WiFiServer.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ void WiFiServer::begin(uint16_t port, uint8_t backlog) {
7777
}
7878
_listen_pcb = listen_pcb;
7979
_port = _listen_pcb->local_port;
80-
tcp_accept(listen_pcb, &WiFiServer::_s_accept);
8180
tcp_arg(listen_pcb, (void*) this);
81+
tcp_accept(listen_pcb, &WiFiServer::_s_accept);
8282
}
8383

8484
void WiFiServer::setNoDelay(bool nodelay) {
@@ -215,9 +215,15 @@ void WiFiServer::_discard(ClientContext* client) {
215215
}
216216

217217
err_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, err_t err) {
218-
return reinterpret_cast<WiFiServer*>(arg)->_accept(newpcb, err);
218+
if (arg) {
219+
return reinterpret_cast<WiFiServer*>(arg)->_accept(newpcb, err);
220+
} else {
221+
return ERR_OK;
222+
}
219223
}
220224

221225
void WiFiServer::_s_discard(void* server, ClientContext* ctx) {
222-
reinterpret_cast<WiFiServer*>(server)->_discard(ctx);
226+
if (server) {
227+
reinterpret_cast<WiFiServer*>(server)->_discard(ctx);
228+
}
223229
}

0 commit comments

Comments
 (0)