[4.1] ce079ac Finish range delivery processing when the range is delivered.

Martin Blix Grydeland martin at varnish-software.com
Mon Nov 28 14:25:05 CET 2016


commit ce079acd6da9e5a865c78cecf7273d6dc4a0cb1d
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Nov 22 16:38:33 2016 +0100

    Finish range delivery processing when the range is delivered.
    
    When doing range delivery, make the delivery processing finish early
    when all of the bytes of the requested range has been delivered. This
    to avoid waiting around for a slow fetch to finish before handling the
    next request on the connection.
    
    Fixes: #2035

diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 6c053fc..bdbee9f 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -48,7 +48,6 @@ static int __match_proto__(vdp_bytes)
 vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
     const void *ptr, ssize_t len)
 {
-	int retval = 0;
 	ssize_t l;
 	const char *p = ptr;
 	struct vrg_priv *vrg_priv;
@@ -76,11 +75,11 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
 	if (l > len)
 		l = len;
 	if (l > 0)
-		retval = VDP_bytes(req, act, p, l);
+		(void)VDP_bytes(req, act, p, l);
 	else if (act > VDP_NULL)
-		retval = VDP_bytes(req, act, p, 0);
+		(void)VDP_bytes(req, act, p, 0);
 	vrg_priv->range_off += len;
-	return (retval);
+	return (vrg_priv->range_off >= vrg_priv->range_high ? 1 : 0);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishtest/tests/r02035.vtc b/bin/varnishtest/tests/r02035.vtc
new file mode 100644
index 0000000..d74dd00
--- /dev/null
+++ b/bin/varnishtest/tests/r02035.vtc
@@ -0,0 +1,34 @@
+varnishtest "Streaming range early finish"
+
+server s1 {
+	non-fatal
+	rxreq
+	txresp -nolen -hdr "Content-Length: 11"
+	# Delay to get around Nagle. Without the delay the body bytes
+	# would be in the same packet as the headers, and would end
+	# up as pipelined data. Pipelined data wouldn't create a streaming
+	# data event, breaking the test case.
+	delay 0.5
+	send_n 10 "A"
+	# Sema r1 halts the backend thread until client c1 is finished.
+	sema r1 sync 2
+	send "B"
+} -start
+
+varnish v1 -vcl+backend {
+} -start
+
+client c1 {
+	txreq -hdr "Range: bytes=0-4"
+	rxresp
+	expect resp.status == 206
+	expect resp.bodylen == 5
+
+	# The client thread should be ready to accept another request:
+	txreq -hdr "Range: bytes=5-9"
+	rxresp
+	expect resp.status == 206
+	expect resp.bodylen == 5
+
+	sema r1 sync 2
+} -run



More information about the varnish-commit mailing list