From 7b26986f8cff7c0741bb14441967cc95b2ae2033 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Sun, 10 Jan 2021 17:54:21 +0100
Subject: [PATCH] CONNECT(): try again if the socket buffer is drained

Works around test1061 being flaky on ElectroBSD.
---
 lib/http_proxy.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/http_proxy.c b/lib/http_proxy.c
index b826e6fed..61bb87a3d 100644
--- a/lib/http_proxy.c
+++ b/lib/http_proxy.c
@@ -340,9 +340,11 @@ static CURLcode CONNECT(struct connectdata *conn,
         /* Read one byte at a time to avoid a race condition. Wait at most one
            second before looping to ensure continuous pgrsUpdates. */
         result = Curl_read(conn, tunnelsocket, &byte, 1, &gotbytes);
-        if(result == CURLE_AGAIN)
-          /* socket buffer drained, return */
-          return CURLE_OK;
+        if(result == CURLE_AGAIN) {
+          /* socket buffer drained, try again */
+          infof(data, "Socket buffer drained. Trying again\n");
+          continue;
+        }
 
         if(Curl_pgrsUpdate(conn))
           return CURLE_ABORTED_BY_CALLBACK;
-- 
2.30.0


