[master] 6f50a00 Implement fail in vcl_(miss|pass|pipe|purge){}

Poul-Henning Kamp phk at FreeBSD.org
Mon Feb 6 22:45:06 CET 2017


commit 6f50a00f80c7f74b2a8b18bb80593f58b74816fd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 6 21:43:30 2017 +0000

    Implement fail in vcl_(miss|pass|pipe|purge){}

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index e50d132..5463e56 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -519,6 +519,9 @@ cnt_miss(struct worker *wrk, struct req *req)
 			(void)HSH_DerefObjCore(wrk, &req->stale_oc, 0);
 		req->req_step = R_STP_FETCH;
 		return (REQ_FSM_MORE);
+	case VCL_RET_FAIL:
+		req->req_step = R_STP_VCLFAIL;
+		break;
 	case VCL_RET_SYNTH:
 		req->req_step = R_STP_SYNTH;
 		break;
@@ -553,6 +556,9 @@ cnt_pass(struct worker *wrk, struct req *req)
 
 	VCL_pass_method(req->vcl, wrk, req, NULL, NULL);
 	switch (wrk->handling) {
+	case VCL_RET_FAIL:
+		req->req_step = R_STP_VCLFAIL;
+		break;
 	case VCL_RET_SYNTH:
 		req->req_step = R_STP_SYNTH;
 		break;
@@ -837,6 +843,9 @@ cnt_purge(struct worker *wrk, struct req *req)
 	case VCL_RET_RESTART:
 		req->req_step = R_STP_RESTART;
 		break;
+	case VCL_RET_FAIL:
+		req->req_step = R_STP_VCLFAIL;
+		break;
 	case VCL_RET_SYNTH:
 		req->req_step = R_STP_SYNTH;
 		break;
diff --git a/bin/varnishtest/tests/v00051.vtc b/bin/varnishtest/tests/v00051.vtc
index 3a04517..308ad55 100644
--- a/bin/varnishtest/tests/v00051.vtc
+++ b/bin/varnishtest/tests/v00051.vtc
@@ -8,9 +8,10 @@ server s1 {
 varnish v1 -vcl+backend {
 	import debug;
 	sub vcl_recv {
-		if (req.http.foo == "pipe") {
-			return(pipe);
-		}
+		if (req.http.foo == "pipe") { return(pipe); }
+		if (req.http.foo == "pass") { return(pass); }
+		if (req.http.foo == "purge") { return(purge); }
+		if (req.http.foo == "miss") { return(hash); }
 		if (req.http.foo == "bar") {
 			return(synth(748));
 		}
@@ -25,12 +26,30 @@ varnish v1 -vcl+backend {
 			set req.http.not = "Should not happen";
 		}
 	}
+	sub vcl_miss {
+		if (req.http.foo == "miss") {
+			debug.fail();
+			set req.http.not = "Should not happen";
+		}
+	}
 	sub vcl_pipe {
 		if (req.http.foo == "pipe") {
 			debug.fail();
 			set req.http.not = "Should not happen";
 		}
 	}
+	sub vcl_pass {
+		if (req.http.foo == "pass") {
+			debug.fail();
+			set req.http.not = "Should not happen";
+		}
+	}
+	sub vcl_purge {
+		if (req.http.foo == "purge") {
+			debug.fail();
+			set req.http.not = "Should not happen";
+		}
+	}
 	sub vcl_synth {
 		if (resp.status == 748) {
 			debug.fail();
@@ -139,9 +158,69 @@ client c1 {
 	expect resp.reason == "VCL failed"
 } -run
 
+varnish v1 -expect sc_vcl_failure == 5
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_pass, no handling in vcl_synth
+
+logexpect l1 -v v1 -g raw {
+	expect * 1014	VCL_call	"PASS"
+	expect 0 1014	Debug		"Forced failure"
+	expect 0 1014	VCL_return	"fail"
+} -start
+
+client c1 {
+	txreq -hdr "foo: pass"
+	rxresp
+	expect resp.status == 503
+	expect resp.reason == "VCL failed"
+} -run
+
+varnish v1 -expect sc_vcl_failure == 6
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_purge, no handling in vcl_synth
+
+logexpect l1 -v v1 -g raw {
+	expect * 1016	VCL_call	"PURGE"
+	expect 0 1016	Debug		"Forced failure"
+	expect 0 1016	VCL_return	"fail"
+} -start
+
+client c1 {
+	txreq -hdr "foo: purge"
+	rxresp
+	expect resp.status == 503
+	expect resp.reason == "VCL failed"
+} -run
+
+varnish v1 -expect sc_vcl_failure == 7
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_miss, no handling in vcl_synth
+
+logexpect l1 -v v1 -g raw {
+	expect * 1018	VCL_call	"MISS"
+	expect 0 1018	Debug		"Forced failure"
+	expect 0 1018	VCL_return	"fail"
+} -start
+
+client c1 {
+	txreq -url /x -hdr "foo: miss"
+	rxresp
+	expect resp.status == 503
+	expect resp.reason == "VCL failed"
+} -run
+
 delay 1
 
-varnish v1 -expect sc_vcl_failure == 5
+varnish v1 -expect sc_vcl_failure == 8
 
 logexpect l1 -wait
 
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 14e50a1..285f126 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -98,7 +98,7 @@ returns = (
 	),
 	('pass',
 		"C",
-		('synth', 'restart', 'fetch',)
+		('fail', 'synth', 'restart', 'fetch',)
 	),
 	('hash',
 		"C",
@@ -106,11 +106,11 @@ returns = (
 	),
 	('purge',
 		"C",
-		('synth', 'restart',)
+		('fail', 'synth', 'restart',)
 	),
 	('miss',
 		"C",
-		('synth', 'restart', 'pass', 'fetch',)
+		('fail', 'synth', 'restart', 'pass', 'fetch',)
 	),
 	('hit',
 		"C",



More information about the varnish-commit mailing list