We should revisit this later to check if we don't close the backend connection
unnecessarily.

Fixes #1638

>From 2fffad712305b0a6e3bbf1db6d64a3f47640fc07 Mon Sep 17 00:00:00 2001
From: Nils Goroll <[email protected]>
Date: Mon, 1 Dec 2014 10:15:30 +0100
Subject: [PATCH] Finish the director (and close the backend connection) also
 for retry in backend_error

We should revisit this later to check if we don't close the backend connection
unnecessarily.

Fixes #1638
---
 bin/varnishd/cache/cache_fetch.c | 28 +++++++++++++++++++----
 bin/varnishtest/tests/r01638.vtc | 49 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 5 deletions(-)
 create mode 100644 bin/varnishtest/tests/r01638.vtc

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 08f253f..b825aef 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -212,6 +212,23 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
 }
 
 /*--------------------------------------------------------------------
+ * Prepare the busyobj for a retry
+ *
+ * XXX: re-check doclose: Do we really close in all the right situatons here?
+ *      Not closing unnecessarily?
+ *
+ */
+
+static void
+vbf_prepare_retry(struct busyobj *bo) {
+	bo->doclose = SC_RESP_CLOSE;
+	if (bo->director_state != DIR_S_NULL)
+		VDI_Finish(bo->director_resp, bo->wrk, bo);
+	bo->doclose = SC_NULL;
+	bo->retries++;
+}
+
+/*--------------------------------------------------------------------
  * Start a new VSL transaction and try again
  */
 
@@ -405,10 +422,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 	}
 
 	if (wrk->handling == VCL_RET_RETRY) {
-		bo->doclose = SC_RESP_CLOSE;
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
-		bo->doclose = SC_NULL;
-		bo->retries++;
+		vbf_prepare_retry(bo);
 		if (bo->retries <= cache_param->max_retries)
 			return (F_STP_RETRY);
 		VSLb(bo->vsl, SLT_VCL_Error,
@@ -769,8 +783,12 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 	if (wrk->handling == VCL_RET_RETRY) {
 		VSB_delete(bo->synth_body);
 		bo->synth_body = NULL;
-		if (bo->retries++ < cache_param->max_retries)
+
+		vbf_prepare_retry(bo);
+
+		if (bo->retries <= cache_param->max_retries)
 			return (F_STP_RETRY);
+
 		return (F_STP_FAIL);
 	}
 
diff --git a/bin/varnishtest/tests/r01638.vtc b/bin/varnishtest/tests/r01638.vtc
new file mode 100644
index 0000000..0284047
--- /dev/null
+++ b/bin/varnishtest/tests/r01638.vtc
@@ -0,0 +1,49 @@
+varnishtest "Test retry of straight insufficient bytes pass-fetch no-sream"
+
+server s1 {
+	rxreq
+	txresp -hdr "Content-Length: 10000" -nolen -bodylen 5000
+}
+
+server s2 {
+	rxreq
+	txresp -bodylen 5
+}
+
+server s1 -start
+server s2 -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		return (pass);
+	}
+	sub vcl_backend_fetch {
+		set bereq.between_bytes_timeout = 10s;
+		if (bereq.retries == 0) {
+			set bereq.backend = s1;
+		} else {
+			set bereq.backend = s2;
+		}
+	}
+	sub vcl_backend_response {
+		set beresp.do_stream = false;
+	}
+	sub vcl_backend_error {
+		if (bereq.retries == 0) {
+			return (retry);
+		} else {
+			return (deliver);
+		}
+	}
+} -start
+
+client c1 {
+	timeout 10
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+	expect resp.bodylen == 5
+} -run
+
+server s1 -wait
+server s2 -wait
-- 
2.1.1

_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to