Skip to content

Truly independent web browser

Meta: Backport curl’s fix for reusing connections with stray input

sideshowbarker0356ef543a3c
diff --git a/Meta/CMake/flatpak/org.ladybird.Ladybird.json b/Meta/CMake/flatpak/org.ladybird.Ladybird.json
index a5aa6cd0a38..57168dd68d4 100644
--- a/Meta/CMake/flatpak/org.ladybird.Ladybird.json
+++ b/Meta/CMake/flatpak/org.ladybird.Ladybird.json
@@ -803,6 +803,10 @@
{
"type": "patch",
"path": "../vcpkg/overlay-ports/curl/wake-all-pending-transfers.patch"
+ },
+ {
+ "type": "patch",
+ "path": "../vcpkg/overlay-ports/curl/poll-idle-connection-input.patch"
}
],
"config-opts": [
diff --git a/Meta/CMake/vcpkg/overlay-ports/curl/poll-idle-connection-input.patch b/Meta/CMake/vcpkg/overlay-ports/curl/poll-idle-connection-input.patch
new file mode 100644
index 00000000000..28ad4d3de59
--- /dev/null
+++ b/Meta/CMake/vcpkg/overlay-ports/curl/poll-idle-connection-input.patch
@@ -0,0 +1,39 @@
+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. */
diff --git a/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake b/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake
index a5e9b7ee59c..57eb865a9d4 100644
--- a/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake
+++ b/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake
@@ -1,10 +1,13 @@
-# FIXME: Send the patch upstream. RequestServer needs it to use CURLOPT_PIPEWAIT, and goes without when it is missing.
-# NB: This is vcpkg's own curl port with one more patch. To update curl, update the version in vcpkg.json here.
-set(ladybird_curl_patch "${CMAKE_CURRENT_LIST_DIR}/wake-all-pending-transfers.patch")
+# FIXME: Send wake-all-pending-transfers.patch upstream. RequestServer needs it to use CURLOPT_PIPEWAIT, and goes without
+# when it is missing.
+# FIXME: Drop poll-idle-connection-input.patch once curl is updated past 8.23.0: It backports curl/curl@ef6b17cf12d4, which
+# keeps an HTTP/1.1 connection with stray input pending from being reused.
+# NB: This is vcpkg's own curl port with two more patches. To update curl, update the version in vcpkg.json here.
+set(ladybird_curl_patches "${CMAKE_CURRENT_LIST_DIR}/wake-all-pending-transfers.patch" "${CMAKE_CURRENT_LIST_DIR}/poll-idle-connection-input.patch")
set(CURRENT_PORT_DIR "${VCPKG_ROOT_DIR}/ports/curl")
macro(vcpkg_from_github)
- _vcpkg_from_github(${ARGN} "${ladybird_curl_patch}")
+ _vcpkg_from_github(${ARGN} ${ladybird_curl_patches})
endmacro()
include("${CURRENT_PORT_DIR}/portfile.cmake")
diff --git a/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json b/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json
index bacecc3cefe..bfb54e02900 100644
--- a/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json
+++ b/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json
@@ -1,7 +1,7 @@
{
"name": "curl",
"version": "8.23.0",
- "port-version": 1,
+ "port-version": 2,
"description": "A library for transferring data with URLs",
"homepage": "https://curl.se/",
"license": "curl AND ISC AND BSD-3-Clause",
diff --git a/vcpkg.json b/vcpkg.json
index f33768ad4af..e669336b0b0 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -288,7 +288,7 @@
},
{
"name": "curl",
- "version": "8.23.0#1"
+ "version": "8.23.0#2"
},
{
"name": "dav1d",