From 6ff0d33ca4ec649c37b8a75d14ee9e624ea94ddd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 13:40:24 -1000 Subject: [PATCH] [api] Add safety check for full write in write_raw_iov_ before enqueue When called directly (not via write_raw_fast_iov_), sent could equal total_write_len. Check before enqueueing to avoid a no-op enqueue. --- esphome/components/api/api_frame_helper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index f46693a4e8..d088a75c8a 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -155,6 +155,10 @@ APIError APIFrameHelper::write_raw_iov_(const struct iovec *iov, int iovcnt, uin } } + // Full write completed (possible when called directly, not via write_raw_fast_iov_) + if (sent == static_cast(total_write_len)) + return APIError::OK; + // Queue unsent data into overflow buffer if (!this->overflow_buf_.enqueue_iov(iov, iovcnt, total_write_len, static_cast(sent))) { HELPER_LOG("Overflow buffer full, dropping connection");