--- /dev/null
+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
-- 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)
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
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
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