From 482d862bcbf813f5a8393ac05a2c31c647fc2984 Mon Sep 17 00:00:00 2001 From: lainon1 <271530700+lainon1@users.noreply.github.com> Date: Mon, 6 Apr 2026 13:03:02 +0100 Subject: [PATCH] server : handle unsuccessful sink.write in chunked stream provider (#21478) Check the return value of sink.write() in the chunked content provider and return false when the write fails, matching cpp-httplib's own streaming contract. This prevents logging chunks as sent when the sink rejected them and properly aborts the stream on connection failure. --- tools/server/server-http.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/server/server-http.cpp b/tools/server/server-http.cpp index be2af26223..37e7cbe9c4 100644 --- a/tools/server/server-http.cpp +++ b/tools/server/server-http.cpp @@ -397,8 +397,9 @@ static void process_handler_response(server_http_req_ptr && request, server_http std::string chunk; bool has_next = response->next(chunk); if (!chunk.empty()) { - // TODO: maybe handle sink.write unsuccessful? for now, we rely on is_connection_closed() - sink.write(chunk.data(), chunk.size()); + if (!sink.write(chunk.data(), chunk.size())) { + return false; + } SRV_DBG("http: streamed chunk: %s\n", chunk.c_str()); } if (!has_next) {