mirror of
https://github.com/esphome/esphome.git
synced 2026-09-16 17:48:40 +00:00
[web_server_idf] Drop pre-disconnected sessions before on_connect_
If fd_ is already 0 when the main loop adopts an incoming session, the client closed before we got here. Delete the session immediately instead of pushing it into sessions_ and firing on_connect_ on a dead socket.
This commit is contained in:
@@ -503,14 +503,16 @@ bool AsyncEventSource::loop() {
|
||||
this->has_pending_sessions_.store(false, std::memory_order_relaxed);
|
||||
}
|
||||
for (auto *rsp : incoming) {
|
||||
// Already disconnected? Drop it; skip on_connect_/prime on a dead session.
|
||||
if (rsp->fd_.load() == 0) {
|
||||
delete rsp; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
continue;
|
||||
}
|
||||
this->sessions_.push_back(rsp);
|
||||
if (this->on_connect_) {
|
||||
this->on_connect_(rsp);
|
||||
}
|
||||
// Already disconnected? Cleanup pass below will delete it.
|
||||
if (rsp->fd_.load() != 0) {
|
||||
rsp->prime_();
|
||||
}
|
||||
rsp->prime_();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user