Skip to content

Truly independent web browser

1.7 KB
Raw Blame
From: Ladybird backport of curl/curl@ef6b17cf12d4
Subject: conncache: poll an idle connection for pending input on every reuse

diff --git a/lib/conncache.c b/lib/conncache.c
index 2f759bed2f01..157db0f2d83a 100644
--- a/lib/conncache.c
+++ b/lib/conncache.c
@@ -1044,11 +1044,20 @@ bool Curl_cpool_conn_seems_healthy(struct connectdata *conn,
 {
   struct Curl_easy *admin;
   bool healthy = TRUE;
+  bool poll_input;
 
   DEBUGASSERT(!data->conn);
   if(cpool_conn_can_be_closed(conn) && cpool_conn_too_old(data, conn, pnow))
     return FALSE;
-  if((curlx_ptimediff_ms(pnow, &conn->created) - conn->lastchecked_ms) < 1000)
+
+  /* An idle, non-multiplexed connection must not be reused when it has
+   * input pending (RFC 9112, section 9.2), so that is polled on every
+   * reuse. The once a second limit only applies to the other checks. */
+  poll_input = cpool_conn_can_be_closed(conn) &&
+    !Curl_conn_is_multiplex(conn, FIRSTSOCKET) &&
+    !conn->scheme->run->connection_is_dead;
+  if(!poll_input &&
+     (curlx_ptimediff_ms(pnow, &conn->created) - conn->lastchecked_ms) < 1000)
     return TRUE;
 
   admin = Curl_get_admin(data);
@@ -1063,8 +1072,7 @@ bool Curl_cpool_conn_seems_healthy(struct connectdata *conn,
     Curl_attach_connection(admin, conn, FALSE);
     healthy = Curl_conn_is_alive(admin, conn, &input_pending);
     Curl_detach_connection(admin);
-    if(healthy && input_pending && cpool_conn_can_be_closed(conn) &&
-       !Curl_conn_is_multiplex(conn, FIRSTSOCKET)) {
+    if(healthy && input_pending && poll_input) {
       /* Non-multiplexed connections without attached transfers should
        * not have input pending. The input might be a TLS Notify Close,
        * for all we know. */