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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user