[master] c15eefb add return(restart) from vcl_recv

Nils Goroll nils.goroll at uplex.de
Fri Dec 29 10:38:10 UTC 2017


commit c15eefb1b237f13564a3453618ede6265396347b
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Dec 26 16:19:24 2017 +0100

    add return(restart) from vcl_recv
    
    This is already possible with some overhead (for example with a
    de-tour via vcl_pass), but I see absolutely no reason why we should
    not allow direct restarts from recv.
    
    The use case is to rewrite the request and re-start processing of the
    rewritten request as if it was received as such. This is also possible
    already with some vcl sub juggling, but is complicated by the VCL call
    loop detection. Use of restarts avoids this complication and is safe
    due to max_restarts.

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 40d87ba..142425c 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -918,6 +918,9 @@ cnt_recv(struct worker *wrk, struct req *req)
 	case VCL_RET_SYNTH:
 		req->req_step = R_STP_SYNTH;
 		break;
+	case VCL_RET_RESTART:
+		req->req_step = R_STP_RESTART;
+		break;
 	case VCL_RET_FAIL:
 		req->req_step = R_STP_VCLFAIL;
 		break;
diff --git a/bin/varnishtest/tests/b00019.vtc b/bin/varnishtest/tests/b00019.vtc
index 5336478..b5e69c1 100644
--- a/bin/varnishtest/tests/b00019.vtc
+++ b/bin/varnishtest/tests/b00019.vtc
@@ -1,4 +1,4 @@
-varnishtest "Check that max_restarts works and that we don't fall over"
+varnishtest "Check that max_restarts outside vcl_recv works and that we don't fall over"
 
 server s1 {
 	rxreq
diff --git a/bin/varnishtest/tests/b00024.vtc b/bin/varnishtest/tests/b00024.vtc
new file mode 100644
index 0000000..e34817d
--- /dev/null
+++ b/bin/varnishtest/tests/b00024.vtc
@@ -0,0 +1,48 @@
+varnishtest "Check that max_restarts from vcl_recv works and that we don't fall over"
+
+varnish v1 -vcl {
+	backend dummy { .host = "${bad_backend}"; }
+
+	sub vcl_recv {
+	       return (restart);
+	}
+
+	sub vcl_synth {
+		# when we end up here, we have _exceeded_ the number
+		# allowed restarts
+		if (req.restarts == 3) {
+			set resp.status = 200;
+			set resp.reason = "restart=3";
+		} elsif (req.restarts > 3) {
+			set resp.status = 501;
+			set resp.reason = "restart>3";
+		} elsif (req.restarts < 3) {
+			set resp.status = 500;
+			set resp.reason = "restart<3";
+		}
+	}
+} -start
+
+varnish v1 -cliok "param.set max_restarts 2"
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+} -run
+
+varnish v1 -cliok "param.set max_restarts 3"
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 501
+} -run
+
+varnish v1 -cliok "param.set max_restarts 1"
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 500
+} -run
diff --git a/doc/changes.rst b/doc/changes.rst
index 4d1f91d..b09221b 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -47,6 +47,8 @@ VCL and bundled VMODs
 
 * workspace overflows in ``std.syslog()`` are ignored
 
+* added ``return(restart)`` from ``vcl_recv{}``
+
 Logging / statistics
 --------------------
 
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 398b658..40d7556 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -93,7 +93,7 @@ returns = (
 
 	('recv',
 		"C",
-		('fail', 'synth', 'pass', 'pipe', 'hash', 'purge', 'vcl')
+		('fail', 'synth', 'restart', 'pass', 'pipe', 'hash', 'purge', 'vcl')
 	),
 	('pipe',
 		"C",


More information about the varnish-commit mailing list