1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-26 23:22:21 +01:00

Improve shutdown reliability when tx buffer is full (#9043)

This commit is contained in:
J. Nick Koston
2025-06-11 05:08:23 -05:00
committed by GitHub
parent 3411e45a0a
commit e8aa7cff36
3 changed files with 18 additions and 2 deletions

View File

@@ -496,11 +496,15 @@ void APIServer::on_shutdown() {
this->socket_ = nullptr;
}
// Change batch delay to 5ms for quick flushing during shutdown
this->batch_delay_ = 5;
// Send disconnect requests to all connected clients
for (auto &c : this->clients_) {
if (!c->send_message(DisconnectRequest())) {
// If we can't send the disconnect request, mark for immediate closure
c->next_close_ = true;
// If we can't send the disconnect request directly (tx_buffer full),
// schedule it in the batch so it will be sent with the 5ms timer
c->schedule_message_(nullptr, &APIConnection::try_send_disconnect_request, DisconnectRequest::MESSAGE_TYPE);
}
}
}