]> git.kaiwu.me - haproxy.git/commitdiff
REGTESTS: filters: Record Lua callback waits across backend EOF
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 2 Oct 2026 19:28:21 +0000 (21:28 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:36 +0000 (16:17 +0200)
While exercising callback resumption, a complete chunked response could
be lost when the backend closed while Lua filters were waiting. The
related EOF race was also observed with legacy filters on the pre-series
build; it is independent of instance parsing and sequencing.

Keep an EOF reproducer separate from the passing resumption test, which
uses a barrier to hold the backend open. Exercise legacy and instance
chains and keep-alive reuse, and mark the test broken until the EOF race
is fixed. Allow the shared probes to configure their wait delay.

reg-tests/filters/lua-eof.vtc [new file with mode: 0644]
reg-tests/filters/lua-probe.lua

diff --git a/reg-tests/filters/lua-eof.vtc b/reg-tests/filters/lua-eof.vtc
new file mode 100644 (file)
index 0000000..740beab
--- /dev/null
@@ -0,0 +1,104 @@
+varnishtest "Waiting Lua filters drain a complete response followed by backend EOF"
+
+#REGTEST_TYPE=broken
+
+feature cmd "$HAPROXY_PROGRAM -cc 'feature(LUA)'"
+feature ignore_unknown_macro
+
+# A backend closing after a complete chunked response can make the stream
+# close before waiting Lua callbacks resume. This also occurs with legacy
+# filters before the instance refactoring. Keep the reproducer separate
+# from the passing resumption test, which holds the backend open with a barrier.
+server s1 {
+    rxreq
+    txresp -body "first response"
+    rxreq
+    txresp -nolen -hdr "Transfer-Encoding: chunked"
+    chunked "complete response"
+    chunked ""
+} -start
+
+haproxy h1 -conf {
+    global
+        nbthread 1
+        tune.lua.bool-sample-conversion normal
+        lua-load "${testdir}/lua-probe.lua"
+    defaults
+        mode http
+        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+        timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+        timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+    frontend fe
+        bind "fd@${fe}"
+        filter lua.probe-a F a wait 2 20
+        filter lua.probe-b F b wait 0 20
+        default_backend be
+    backend be
+        http-reuse always
+        filter lua.probe-a B a wait 3 20
+        filter lua.probe-b B b wait 2 20
+        server s1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe_sock} {
+    txreq -req POST -body "request body"
+    rxresp
+    expect resp.status == 200
+    expect resp.body == "first response"
+    txreq -req POST -nolen -hdr "Transfer-Encoding: chunked"
+    chunked "request "
+    chunked "body"
+    chunked ""
+    rxresp
+    expect resp.status == 200
+    expect resp.http.x-probe-order == "F.a;F.b;B.a;B.b;"
+    expect resp.http.x-probe-errors == <undef>
+    expect resp.body == "complete response"
+} -run
+
+server s2 {
+    rxreq
+    txresp -body "first response"
+    rxreq
+    txresp -nolen -hdr "Transfer-Encoding: chunked"
+    chunked "complete response"
+    chunked ""
+} -start
+
+haproxy h2 -conf {
+    global
+        nbthread 1
+        tune.lua.bool-sample-conversion normal
+        lua-load "${testdir}/lua-probe.lua"
+    defaults
+        mode http
+        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+        timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+        timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+    frontend fe
+        bind "fd@${fe}"
+        filter-config lua id probe-a enabled F a wait 2 20
+        filter-config lua id probe-b enabled F b wait 0 20
+        default_backend be
+    backend be
+        http-reuse always
+        filter-config lua id probe-a enabled B a wait 3 20
+        filter-config lua id probe-b enabled B b wait 2 20
+        server s2 ${s2_addr}:${s2_port}
+} -start
+
+client c2 -connect ${h2_fe_sock} {
+    txreq -req POST -body "request body"
+    rxresp
+    expect resp.status == 200
+    expect resp.body == "first response"
+    txreq -req POST -nolen -hdr "Transfer-Encoding: chunked"
+    chunked "request "
+    chunked "body"
+    chunked ""
+    rxresp
+    expect resp.status == 200
+    expect resp.http.x-probe-order == "F.a;F.b;B.a;B.b;"
+    expect resp.http.x-probe-errors == <undef>
+    expect resp.body == "complete response"
+} -run
index 846457c1f53703da733a1063a3db85552ff13375..10f8c2eaa27bf6ae1268d01f7d3a9b1c0f4f3f87 100644 (file)
@@ -1,6 +1,6 @@
 -- Reusable HTTP probes. Arguments: scope, tag, mode (headers/data/wait/decline),
--- optional maximum bytes forwarded per payload callback. Only new() mutates
--- the construction counters; all callback state belongs to the stream instance.
+-- optional maximum bytes forwarded per payload callback and wait delay in ms.
+-- Only new() mutates counters; callback state belongs to the stream instance.
 local counters = {}
 
 local function append(msg, header, value)
@@ -33,7 +33,7 @@ local function register(name)
         local side = chn:is_resp() and 2 or 1
         if self.mode == "wait" and not self.start_waited[side] then
             self.start_waited[side] = true
-            filter.wake_time(1)
+            filter.wake_time(self.wait_ms)
             return filter.WAIT
         end
         self.started[side] = true
@@ -49,7 +49,7 @@ local function register(name)
         local side = msg:is_resp() and 2 or 1
         if self.mode == "wait" and not self.headers_waited[side] then
             self.headers_waited[side] = true
-            filter.wake_time(1)
+            filter.wake_time(self.wait_ms)
             return filter.WAIT
         end
         local tag = self.scope .. "." .. self.tag
@@ -91,7 +91,9 @@ local function register(name)
         conf.tag = args[2]
         conf.mode = args[3] or "headers"
         conf.limit = tonumber(args[4]) or 0
+        conf.wait_ms = tonumber(args[5]) or 1
         assert(conf.limit >= 0, "probe payload limit must not be negative")
+        assert(conf.wait_ms > 0, "probe wait delay must be positive")
         return conf
     end)
 end