]> err.no Git - varnish/commitdiff
Error out when reaching max_restarts
authortfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 7 Oct 2008 11:08:43 +0000 (11:08 +0000)
committertfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 7 Oct 2008 11:08:43 +0000 (11:08 +0000)
Partially addresses #280

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3265 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishtest/tests/b00019.vtc [new file with mode: 0644]

index 1bc73f1c81e3e62de43c1b64abca31ff8a8a1aec..a299a6e0f22d5528b264ffa00fc8bd8978ba8700 100644 (file)
@@ -855,6 +855,12 @@ cnt_recv(struct sess *sp)
        AN(sp->director);
 
        VCL_recv_method(sp);
+       if (sp->restarts >= params->max_restarts) {
+               if (sp->err_code == 0)
+                       sp->err_code = 503;
+               sp->step = STP_ERROR;
+               return (0);
+       }
 
        sp->wantbody = (strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD") != 0);
        sp->sendbody = 0;
diff --git a/varnish-cache/bin/varnishtest/tests/b00019.vtc b/varnish-cache/bin/varnishtest/tests/b00019.vtc
new file mode 100644 (file)
index 0000000..2501acb
--- /dev/null
@@ -0,0 +1,48 @@
+# $Id$
+
+test "Check that max_restarts works and that we don't fall over"
+
+server s1 -repeat 6 {
+       rxreq
+       txresp -body "012345\n"
+} -start
+
+varnish v1 -vcl+backend {
+       sub vcl_fetch {
+              restart;
+       }
+
+       sub vcl_error {
+               if (req.restarts == 2) {
+                       set obj.status = 200;
+               } elsif (req.restarts > 2) {
+                       set obj.status = 501;
+               } elsif (req.restarts < 2) {
+                       set obj.status = 500;
+               }
+       }
+} -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