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

Charles Zablit via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 07:57:46 PDT 2026


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

When `WinHttpQueryDataAvailable` fails, it can be because of a timeout. We currently don't handle that case and report success instead.

This patch handles the timeout case by returning an error instead.

List of possible error values:
https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpquerydataavailable#return-value

>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] [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;
 



More information about the llvm-commits mailing list