diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c index c55f688031f..af7a70de0d7 100644 --- a/bin/varnishd/http1/cache_http1_pipe.c +++ b/bin/varnishd/http1/cache_http1_pipe.c @@ -40,6 +40,7 @@ #include "cache_http1.h" #include "vtcp.h" +#include "vtim.h" #include "VSC_vbe.h" @@ -117,7 +118,8 @@ stream_close_t V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a) { struct pollfd fds[2]; - vtim_dur tmo; + vtim_dur tmo, tmo_task; + vtim_real deadline; stream_close_t sc; int i, j; @@ -141,6 +143,10 @@ V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a) fds[1].fd = req->sp->fd; fds[1].events = POLLIN; + deadline = cache_param->deadline_pipe; + if (deadline > 0.) + deadline += req->sp->t_idle; + sc = SC_TX_PIPE; while (fds[0].fd > -1 || fds[1].fd > -1) { fds[0].revents = 0; @@ -148,6 +154,11 @@ V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a) tmo = cache_param->pipe_timeout; if (tmo == 0.) tmo = -1.; + if (deadline > 0.) { + tmo_task = deadline - VTIM_real(); + tmo = (tmo > 0.) ? vmin(tmo, tmo_task) : tmo_task; + tmo = vmax(tmo, 0.); + } i = poll(fds, 2, (int)(tmo * 1e3)); if (i == 0) sc = SC_RX_TIMEOUT; diff --git a/bin/varnishtest/tests/s00013.vtc b/bin/varnishtest/tests/s00013.vtc index 06e89871bf1..e7dd04aee8a 100644 --- a/bin/varnishtest/tests/s00013.vtc +++ b/bin/varnishtest/tests/s00013.vtc @@ -10,13 +10,31 @@ server s1 { rxreq txresp -hdr "transfer-encoding: chunked" expect_close + + accept + rxreq + txresp -hdr "transfer-encoding: chunked" + expect_close + + accept + non_fatal + rxreq + txresp -hdr "transfer-encoding: chunked" + loop 20 { + chunkedlen 1 + delay 0.1 + } } -start varnish v1 -cliok "param.set pipe_timeout 0s" +varnish v1 -cliok "param.set deadline_pipe 0s" varnish v1 -vcl+backend "" -start -logexpect l1 -v v1 -q "Timestamp:PipeSess[2] > 1.0" { - expect 1001 * ReqMethod PIPE +logexpect l1 -v v1 -g raw -q SessClose { + expect 1000 * SessClose {^TX_PIPE 1\.} + expect 1003 * SessClose {^RX_TIMEOUT 0\.} + expect 1006 * SessClose {^RX_TIMEOUT 1\.} + expect 1009 * SessClose {^RX_TIMEOUT 1\.} } -start client c1 { @@ -25,11 +43,20 @@ client c1 { rxresp } -run -logexpect l1 -wait +varnish v1 -cliok "param.set pipe_timeout 500ms" +varnish v1 -cliok "param.set deadline_pipe 0s" +client c1 -run + +varnish v1 -cliok "param.set pipe_timeout 0s" +varnish v1 -cliok "param.set deadline_pipe 1.1s" +client c1 -run varnish v1 -cliok "param.set pipe_timeout 500ms" +varnish v1 -cliok "param.set deadline_pipe 1.1s" client c1 -run -varnish v1 -expect MAIN.s_pipe == 2 +logexpect l1 -wait + +varnish v1 -expect MAIN.s_pipe == 4 varnish v1 -expect MAIN.sc_tx_pipe == 1 -varnish v1 -expect MAIN.sc_rx_timeout == 1 +varnish v1 -expect MAIN.sc_rx_timeout == 3