mirror of
https://github.com/esphome/esphome.git
synced 2026-02-16 06:19:32 -07:00
[api] Fix ESP8266 noise API handshake deadlock and prompt socket cleanup
Two fixes for ESP8266 with noise encryption: 1. Cache socket ready() before the handshake loop. On ESP8266 LWIP raw TCP, ready() returns the live state (false once rx buffer is consumed), unlike ESP32 where it is cached until the next main loop. Re-checking each iteration blocked handshake writes that must follow reads, deadlocking the handshake. 2. Process client removal immediately after loop() instead of deferring to the next server loop iteration. This closes the socket promptly to free LWIP PCB resources and prevent retransmit crashes on ESP8266.
This commit is contained in:
@@ -148,12 +148,16 @@ void APIServer::loop() {
|
||||
while (client_index < this->clients_.size()) {
|
||||
auto &client = this->clients_[client_index];
|
||||
|
||||
// Common case: process active client
|
||||
if (!client->flags_.remove) {
|
||||
client->loop();
|
||||
}
|
||||
// Handle disconnection promptly - close socket to free LWIP PCB
|
||||
// resources and prevent retransmit crashes on ESP8266.
|
||||
if (client->flags_.remove) {
|
||||
// Rare case: handle disconnection (don't increment - swapped element needs processing)
|
||||
this->remove_client_(client_index);
|
||||
} else {
|
||||
// Common case: process active client
|
||||
client->loop();
|
||||
client_index++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user