From 20ea994624213c327f7a8d11d05ffa18823aba33 Mon Sep 17 00:00:00 2001
From: Daniel Lenar <dlenar@vailsys.com>
Date: Tue, 2 Sep 2025 10:24:39 -0500
Subject: [PATCH] BUG/MINOR: checks: Fix connection reuse for http

Fix to allow both http and https to be able to reuse connections.
Previosuly, only http backends were eliglbe for connection reuse.

When check-reuse-pool was enabled, the connection was still being marked
private. Since it was being marked private, it didn't allow for
connection to be reused. The fix is to check if check-reuse-pool is
enabled, set the connection hash key and make sure it is not marked
private.

When check-reuse-pool is enabled, make sure that http checks read all
the data. If there was still pending data, the connection would be
closed and not able to be reused.
---
 src/tcpcheck.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index 71712ac9d..f02b3a1ca 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -1216,7 +1216,7 @@ static inline int tcpcheck_use_nondefault_connect(const struct check *check,
 	return check->mux_proto || connect->mux_proto ||
 	  is_addr(&check->addr) || is_addr(&connect->addr) ||
 	  check->port || connect->port || connect->port_expr ||
-	  check->use_ssl || check->alpn_len || connect->alpn_len ||
+	  check->alpn_len || connect->alpn_len ||
 	  check->send_proxy || check->via_socks4 ||
 	  (connect->options & TCPCHK_MASK_OPTS_CONNECT);
 }
@@ -1237,6 +1237,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
 	struct xprt_ops *xprt;
 	struct tcpcheck_rule *next;
 	int status, port;
+	int64_t hash = 0;
 
 	TRACE_ENTER(CHK_EV_TCPCHK_CONN, check);
 
@@ -1267,7 +1268,6 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
 	if (!(check->state & CHK_ST_AGENT) && check->reuse_pool &&
 	    !tcpcheck_use_nondefault_connect(check, connect)) {
 		struct ist pool_conn_name = IST_NULL;
-		int64_t hash;
 		int conn_err;
 
 		TRACE_DEVEL("trying connection reuse for check", CHK_EV_TCPCHK_CONN, check);
@@ -1407,7 +1407,12 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
 	if (status != SF_ERR_NONE)
 		goto fail_check;
 
-	conn_set_private(conn);
+	if (check->reuse_pool && !tcpcheck_use_nondefault_connect(check, connect)) {
+		conn->hash_node->node.key = hash;
+	} else {
+		conn_set_private(conn);
+	}
+
 	conn->ctx = check->sc;
 
 #ifdef USE_OPENSSL
@@ -1840,6 +1845,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_expect_http(struct check *check, struct tcp
 	struct htx_sl *sl;
 	struct htx_blk *blk;
 	enum tcpcheck_eval_ret ret = TCPCHK_EVAL_CONTINUE;
+	struct tcpcheck_connect *connect = &rule->connect;
 	struct tcpcheck_expect *expect = &rule->expect;
 	struct buffer *msg = NULL, *tmp = NULL, *nbuf = NULL, *vbuf = NULL;
 	enum healthcheck_status status = HCHK_STATUS_L7RSP;
@@ -1866,6 +1872,9 @@ enum tcpcheck_eval_ret tcpcheck_eval_expect_http(struct check *check, struct tcp
 		goto wait_more_data;
 	}
 
+	if (!last_read && check->reuse_pool && !tcpcheck_use_nondefault_connect(check, connect))
+		goto wait_more_data;
+
 	sl = http_get_stline(htx);
 	check->code = sl->info.res.status;
 
-- 
2.43.5

