From 320e73a0e62c86590dff04cebf01aa59b17ad88f Mon Sep 17 00:00:00 2001
From: Andrea Cocito <andrea@cocito.eu>
Date: Fri, 27 Nov 2026 16:19:58 +0100
Subject: [PATCH 2/2] REGTESTS: http-messaging: cover H1 EOF with buffered
 input
To: haproxy@formilux.org
Cc: cfaulet@haproxy.com

Add a deterministic H2 flow-control reproducer for backend EOF arriving
while the H1 mux still has response body bytes in its input buffer.

The test holds the H2 receive window closed until the backend sends a
complete Content-Length response and closes. It then opens the window in
steps so that only part of the buffered H1 input can be forwarded at once.
On an unpatched kqueue build, HAProxy resets the H2 stream before delivering
the complete body. With the mux-h1 fix, all 16,220 bytes are received.

The test fails on unpatched macOS and FreeBSD kqueue builds and passes
with the fix on development, 3.4.7 and current 3.4.9 sources.
---
 reg-tests/http-messaging/h1_fastfwd_eof.vtc | 71 +++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 reg-tests/http-messaging/h1_fastfwd_eof.vtc

diff --git a/reg-tests/http-messaging/h1_fastfwd_eof.vtc b/reg-tests/http-messaging/h1_fastfwd_eof.vtc
new file mode 100644
index 000000000..e098c6c96
--- /dev/null
+++ b/reg-tests/http-messaging/h1_fastfwd_eof.vtc
@@ -0,0 +1,71 @@
+# File: reg-tests/http-messaging/h1_fastfwd_eof.vtc
+# Created by Andrea "Nemesi" Cocito on 27/11/2026
+# Buffered H1 response data must be forwarded before backend EOF is classified.
+# On kqueue, an EOF event with no socket data can arrive while the H1 mux still
+# holds body bytes. H2 flow control leaves part of those bytes in the H1 input
+# buffer when the producer checks EOF. The unpatched mux resets the H2 stream.
+
+varnishtest "H1 fast forwarding drains buffered input before backend EOF"
+
+feature ignore_unknown_macro
+
+barrier body_started cond 2
+
+server s1 {
+	rxreq
+	txresp -nolen -hdr "content-length: 16220" -bodylen 16220
+	barrier body_started sync
+	delay 0.05
+	shutdown
+} -start
+
+haproxy h1 -conf {
+    global
+	# Keep the complete H1 response in the first socket read, leaving only
+	# a small body remainder in the H1 input buffer after HTX conversion.
+	tune.bufsize 16384
+	tune.maxrewrite 64
+    .if feature(THREAD)
+        thread-groups 1
+    .endif
+
+    defaults
+	mode http
+	timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+	timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
+	timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"
+
+    listen fe
+	bind "fd@${fe}" proto h2
+	server s1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe_sock} {
+	txpri
+	stream 0 {
+		txsettings -winsize 0
+		rxsettings
+		txsettings -ack
+	} -run
+
+	stream 1 {
+		txreq -req "GET" -scheme "http" -url "/"
+		rxhdrs
+		expect resp.status == 200
+		expect resp.http.content-length == "16220"
+		barrier body_started sync
+		# Let the socket queue drain and the kqueue EOF event be delivered.
+		delay 0.2
+		txwinup -size 16192
+		delay 0.1
+		# Ten bytes remain queued in the H2 mux; only ten of the
+		# eighteen bytes in H1 input can be forwarded on this update.
+		txwinup -size 20
+		delay 0.1
+		txwinup -size 8
+		rxdata -all
+		expect resp.bodylen == 16220
+	} -run
+} -run
+
+# END File: reg-tests/http-messaging/h1_fastfwd_eof.vtc
-- 
2.33.0

