From: Christopher Faulet Date: Fri, 2 Oct 2026 19:28:21 +0000 (+0200) Subject: REGTESTS: filters: Record Lua callback waits across backend EOF X-Git-Tag: v3.5-dev9~56 X-Git-Url: https://git.kaiwu.me/$%7BISSUES%7D/static/gitweb.js?a=commitdiff_plain;h=fb842ccd6187f41e97e038dcaeba1c981302d626;p=haproxy.git REGTESTS: filters: Record Lua callback waits across backend EOF 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. --- diff --git a/reg-tests/filters/lua-eof.vtc b/reg-tests/filters/lua-eof.vtc new file mode 100644 index 000000000..740beabbf --- /dev/null +++ b/reg-tests/filters/lua-eof.vtc @@ -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 == + 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 == + expect resp.body == "complete response" +} -run diff --git a/reg-tests/filters/lua-probe.lua b/reg-tests/filters/lua-probe.lua index 846457c1f..10f8c2eaa 100644 --- a/reg-tests/filters/lua-probe.lua +++ b/reg-tests/filters/lua-probe.lua @@ -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