[master] e5efc2c Implement failure in vcl_hash{}

Poul-Henning Kamp phk at FreeBSD.org
Mon Feb 6 11:42:05 CET 2017


commit e5efc2c8dc0d003e5f0fa1a30b598f5949112897
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 6 10:41:16 2017 +0000

    Implement failure in vcl_hash{}

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index b24159b..30fecde 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -752,7 +752,10 @@ cnt_recv(struct worker *wrk, struct req *req)
 
 	SHA256_Init(&sha256ctx);
 	VCL_hash_method(req->vcl, wrk, req, NULL, &sha256ctx);
-	assert(wrk->handling == VCL_RET_LOOKUP);
+	if (wrk->handling == VCL_RET_FAIL)
+		recv_handling = wrk->handling;
+	else
+		assert(wrk->handling == VCL_RET_LOOKUP);
 	SHA256_Final(req->digest, &sha256ctx);
 
 	switch(recv_handling) {
diff --git a/bin/varnishtest/tests/v00051.vtc b/bin/varnishtest/tests/v00051.vtc
index 8800896..d9303c2 100644
--- a/bin/varnishtest/tests/v00051.vtc
+++ b/bin/varnishtest/tests/v00051.vtc
@@ -15,6 +15,11 @@ varnish v1 -vcl+backend {
 			debug.fail();
 		}
 	}
+	sub vcl_hash {
+		if (req.http.foo == "hash") {
+			debug.fail();
+		}
+	}
 	sub vcl_synth {
 		if (resp.status == 748) {
 			debug.fail();
@@ -85,3 +90,24 @@ client c1 {
 varnish v1 -expect sc_vcl_failure == 3
 
 logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_hash, no handling in vcl_synth
+
+logexpect l1 -v v1 -g raw {
+	expect * 1009	VCL_call	"HASH"
+	expect 0 1009	Debug		"Forced failure"
+	expect 0 1009	VCL_return	"fail"
+} -start
+
+client c1 {
+	txreq -hdr "foo: hash"
+	rxresp
+	expect resp.status == 503
+	expect resp.reason == "VCL failed"
+} -run
+
+varnish v1 -expect sc_vcl_failure == 4
+
+logexpect l1 -wait
+
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index ecf4e3f..ef77858 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -102,7 +102,7 @@ returns = (
 	),
 	('hash',
 		"C",
-		('lookup',)
+		('fail', 'lookup',)
 	),
 	('purge',
 		"C",



More information about the varnish-commit mailing list