Hi,

Currently if you want to have all your error handling in a single place,
i.e. vcl_synth{}, and you end up in vcl_backend_error{} you have to either
return retry and then abandon in vcl_backend_fetch{} or return deliver and
in vcl_deliver{} return synth.

I can't think of any reason for not allowing this so the attached patch
lifts this restriction.

Comments? OKs?
From 93ff7f8711ba16ceaf173714c1f04dd4f6454101 Mon Sep 17 00:00:00 2001
From: "Federico G. Schwindt" <[email protected]>
Date: Thu, 9 Apr 2015 14:10:05 +0100
Subject: [PATCH] Allow returning abandon from vcl_backend_error{}

---
 bin/varnishd/cache/cache_fetch.c |  6 ++++--
 bin/varnishtest/tests/b00038.vtc | 25 ++++++++++++++++++++++---
 lib/libvcc/generate.py           |  2 +-
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 38703fe..634c843 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -798,7 +798,8 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 
 	AZ(VSB_finish(bo->synth_body));
 
-	if (wrk->handling == VCL_RET_RETRY) {
+	if (wrk->handling == VCL_RET_RETRY ||
+	    wrk->handling == VCL_RET_ABANDON) {
 		VSB_delete(bo->synth_body);
 		bo->synth_body = NULL;
 
@@ -806,7 +807,8 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 		if (bo->director_state != DIR_S_NULL)
 			VDI_Finish(bo->wrk, bo);
 
-		if (bo->retries++ < cache_param->max_retries)
+		if (wrk->handling == VCL_RET_RETRY &&
+		    bo->retries++ < cache_param->max_retries)
 			return (F_STP_RETRY);
 
 		return (F_STP_FAIL);
diff --git a/bin/varnishtest/tests/b00038.vtc b/bin/varnishtest/tests/b00038.vtc
index 963dc48..b963b4f 100644
--- a/bin/varnishtest/tests/b00038.vtc
+++ b/bin/varnishtest/tests/b00038.vtc
@@ -1,18 +1,37 @@
-varnishtest "vcl_backend_fetch abandon"
+varnishtest "Test abandon from vcl_backend_xxx"
 
 server s1 {
 	rxreq
+	expect req.url == "/bar"
 	txresp
 } -start
 
-varnish v1 -vcl+backend {
+varnish v1 -arg "-pfirst_byte_timeout=0.1" -vcl+backend {
 	sub vcl_backend_fetch {
+		if (bereq.url == "/foo") {
+			return (abandon);
+		}
+	}
+	sub vcl_backend_response {
+		if (bereq.url == "/bar") {
+			return (abandon);
+		}
+	}
+	sub vcl_backend_error {
 		return (abandon);
 	}
 } -start
 
 client c1 {
-	txreq
+	txreq -url /foo
+	rxresp
+	expect resp.status == 503
+
+	txreq -url /bar
+	rxresp
+	expect resp.status == 503
+
+	txreq -url /baz
 	rxresp
 	expect resp.status == 503
 } -run
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 19da0e0..4b35122 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -132,7 +132,7 @@ returns =(
 	),
 	('backend_error',
 		"B",
-		('deliver', 'retry')
+		('deliver', 'retry', 'abandon')
 	),
 
 	###############################################################
-- 
2.1.4

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

Reply via email to