From dbf4c4030a95b610cf86aa576ba7676736f81dc3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 26 Nov 2023 00:10:17 +0100 Subject: [PATCH] conncache: use the closure handle when disconnecting surplus connections Use the closure handle for disconnecting connection cache entries so that anything that happens during the disconnect is not stored and associated with the 'data' handle which already just finished a transfer and it is important that details from the unrelated disconnect does not taint meta-data in the data handle. Like storing the response code. This also adjust test 1506. Unfortunately it also removes a key part of the test that verifies that a connection is closed since when this output vanishes (because the closure handle is used), we don't know exactly that the connection actually gets closed in this test... Reported-by: ohyeaah on github Fixes #12367 Closes #12405 --- lib/conncache.c | 12 ++++++++++-- tests/data/test1506 | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/conncache.c b/lib/conncache.c index a831a94ce1..66f18ecb85 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -389,8 +389,16 @@ bool Curl_conncache_return_conn(struct Curl_easy *data, conn_candidate = Curl_conncache_extract_oldest(data); if(conn_candidate) { - /* the winner gets the honour of being disconnected */ - Curl_disconnect(data, conn_candidate, /* dead_connection */ FALSE); + /* Use the closure handle for this disconnect so that anything that + happens during the disconnect is not stored and associated with the + 'data' handle which already just finished a transfer and it is + important that details from this (unrelated) disconnect does not + taint meta-data in the data handle. */ + struct conncache *connc = data->state.conn_cache; + connc->closure_handle->state.buffer = data->state.buffer; + connc->closure_handle->set.buffer_size = data->set.buffer_size; + Curl_disconnect(connc->closure_handle, conn_candidate, + /* dead_connection */ FALSE); } } diff --git a/tests/data/test1506 b/tests/data/test1506 index 9eb38cf6d1..0a62c0c2a6 100644 --- a/tests/data/test1506 +++ b/tests/data/test1506 @@ -86,7 +86,6 @@ Accept: */* * Connection #0 to host server1.example.com left intact * Connection #1 to host server2.example.com left intact * Connection #2 to host server3.example.com left intact -* Closing connection * Connection #3 to host server4.example.com left intact -- 2.47.3