[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:
J. Nick Koston
2026-04-24 02:59:03 -05:00
parent 82081fc567
commit b1390f1679
@@ -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_();
}
}