mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 08:15:49 +00:00
[web_server_idf] Fix lwIP assertion crash by shutting down sockets on connection close (#11937)
This commit is contained in:
@@ -489,10 +489,18 @@ AsyncEventSourceResponse::AsyncEventSourceResponse(const AsyncWebServerRequest *
|
|||||||
|
|
||||||
void AsyncEventSourceResponse::destroy(void *ptr) {
|
void AsyncEventSourceResponse::destroy(void *ptr) {
|
||||||
auto *rsp = static_cast<AsyncEventSourceResponse *>(ptr);
|
auto *rsp = static_cast<AsyncEventSourceResponse *>(ptr);
|
||||||
ESP_LOGD(TAG, "Event source connection closed (fd: %d)", rsp->fd_.load());
|
int fd = rsp->fd_.exchange(0); // Atomically get and clear fd
|
||||||
// Mark as dead by setting fd to 0 - will be cleaned up in the main loop
|
|
||||||
rsp->fd_.store(0);
|
if (fd > 0) {
|
||||||
// Note: We don't delete or remove from set here to avoid race conditions
|
ESP_LOGD(TAG, "Event source connection closed (fd: %d)", fd);
|
||||||
|
// Immediately shut down the socket to prevent lwIP from delivering more data
|
||||||
|
// This prevents "recv_tcp: recv for wrong pcb!" assertions when the TCP stack
|
||||||
|
// tries to deliver queued data after the session is marked as dead
|
||||||
|
// See: https://github.com/esphome/esphome/issues/11936
|
||||||
|
shutdown(fd, SHUT_RDWR);
|
||||||
|
// Note: We don't close() the socket - httpd owns it and will close it
|
||||||
|
}
|
||||||
|
// Session will be cleaned up in the main loop to avoid race conditions
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper for allowing only unique entries in the queue
|
// helper for allowing only unique entries in the queue
|
||||||
|
|||||||
Reference in New Issue
Block a user