[llvm] [llvm] Report a WinHttpQueryDataAvailable failure instead of ending the body (PR #226514)

Charles Zablit via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 06:49:38 PDT 2026


https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/226514

>From 7b4f76cde26f11f3a6f684263271e0bc261e5cdc Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Fri, 25 Sep 2026 15:54:47 +0100
Subject: [PATCH 1/2] [llvm] Report a WinHttpQueryDataAvailable failure instead
 of ending the body

---
 llvm/lib/HTTP/HTTPClient.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/HTTP/HTTPClient.cpp b/llvm/lib/HTTP/HTTPClient.cpp
index fb3506a238648..73e8ff6b06622 100644
--- a/llvm/lib/HTTP/HTTPClient.cpp
+++ b/llvm/lib/HTTP/HTTPClient.cpp
@@ -427,7 +427,16 @@ Error HTTPClient::perform(const HTTPRequest &Request,
 
   // Read response body
   DWORD BytesAvailable = 0;
-  while (WinHttpQueryDataAvailable(Session->RequestHandle, &BytesAvailable)) {
+  while (true) {
+    // A failure here is not the end of the body: it is how a timeout waiting
+    // for the next chunk reports itself.
+    if (!WinHttpQueryDataAvailable(Session->RequestHandle, &BytesAvailable)) {
+      bool TimedOut = GetLastError() == ERROR_WINHTTP_TIMEOUT;
+      return createStringError(errc::io_error,
+                               TimedOut ? "Timeout was reached"
+                                        : "Failed to read HTTP response");
+    }
+
     if (BytesAvailable == 0)
       break;
 

>From 66cd6e0647e6b6f758b4d7d782d8ceb1979a7e86 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 30 Sep 2026 14:49:00 +0100
Subject: [PATCH 2/2] fixup! [llvm] Report a WinHttpQueryDataAvailable failure
 instead of ending the body

---
 llvm/lib/HTTP/HTTPClient.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/HTTP/HTTPClient.cpp b/llvm/lib/HTTP/HTTPClient.cpp
index 73e8ff6b06622..3fcf57ee02f79 100644
--- a/llvm/lib/HTTP/HTTPClient.cpp
+++ b/llvm/lib/HTTP/HTTPClient.cpp
@@ -443,8 +443,12 @@ Error HTTPClient::perform(const HTTPRequest &Request,
     std::vector<char> Buffer(BytesAvailable);
     DWORD BytesRead = 0;
     if (!WinHttpReadData(Session->RequestHandle, Buffer.data(), BytesAvailable,
-                         &BytesRead))
-      return createStringError(errc::io_error, "Failed to read HTTP response");
+                         &BytesRead)) {
+      bool TimedOut = GetLastError() == ERROR_WINHTTP_TIMEOUT;
+      return createStringError(errc::io_error,
+                               TimedOut ? "Timeout was reached"
+                                        : "Failed to read HTTP response");
+    }
 
     if (BytesRead > 0) {
       if (Error Err =



More information about the llvm-commits mailing list