[master] fe85c10 Handle the case where too many retries are attempted, by returning a 503 reply.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 17 11:58:26 CET 2014


commit fe85c10c5d2c85a3f8efcfc41d4f57c539cae2d9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 17 10:57:56 2014 +0000

    Handle the case where too many retries are attempted, by returning
    a 503 reply.
    
    Fixes #1401

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index afc3cce..f461fa5 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -244,6 +244,8 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
 	VCL_backend_response_method(bo->vcl, wrk, NULL, bo, bo->beresp->ws);
 
 	if (wrk->handling == VCL_RET_RETRY) {
+		if (bo->vbc)
+			VDI_CloseFd(&bo->vbc);
 		bo->retries++;
 		if (bo->retries <= cache_param->max_retries) {
 			// XXX: BereqEnd + BereqAcct ?
@@ -254,10 +256,12 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
 			owid = bo->vsl->wid & VSL_IDENTMASK;
 			bo->vsl->wid = wid | VSL_BACKENDMARKER;
 			VSLb(bo->vsl, SLT_Begin, "bereq %u retry", owid);
-			VDI_CloseFd(&bo->vbc);
 			return (F_STP_STARTFETCH);
 		}
-		INCOMPL();
+		VSLb(bo->vsl, SLT_VCL_Error,
+		    "Too many retries, delivering 503");
+		make_it_503(bo);
+		wrk->handling = VCL_RET_DELIVER;
 	}
 
 	assert(bo->state == BOS_REQ_DONE);
diff --git a/bin/varnishtest/tests/r01401.vtc b/bin/varnishtest/tests/r01401.vtc
new file mode 100644
index 0000000..066974d
--- /dev/null
+++ b/bin/varnishtest/tests/r01401.vtc
@@ -0,0 +1,61 @@
+varnishtest "too many retries"
+
+server s1 {
+	rxreq
+	expect req.url == /1
+	txresp -hdr "foo: bar" -bodylen 5
+
+	accept
+	rxreq
+	expect req.url == /1
+	txresp -hdr "foo: foof" -hdr "Connection: close" -bodylen 7
+
+	accept
+	rxreq
+	expect req.url == /2
+	txresp -hdr "foo: bar" -bodylen 10
+
+	accept
+	rxreq
+	expect req.url == /2
+	txresp -hdr "foo: bar" -bodylen 11
+
+	accept
+	rxreq
+	expect req.url == /2
+	txresp -hdr "foo: bar" -bodylen 12
+
+	accept
+	rxreq
+	expect req.url == /2
+	txresp -hdr "foo: bar" -bodylen 13
+
+	accept
+	rxreq
+	expect req.url == /2
+	txresp -hdr "foo: bar" -bodylen 4
+
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_backend_response {
+		if (beresp.http.foo == "bar") {
+			return (retry);
+		}
+	}
+} -start
+
+client c1 {
+	txreq -url /1
+	rxresp
+	expect resp.http.foo == foof
+	expect resp.bodylen == 7
+} -run
+
+delay .1
+
+client c1 {
+	txreq -url /2
+	rxresp
+	expect resp.status == 503
+} -run



More information about the varnish-commit mailing list