From 608dcbb644d1c0268a889cd21720700b455b5531 Mon Sep 17 00:00:00 2001 From: tfheen Date: Tue, 7 Oct 2008 11:08:43 +0000 Subject: [PATCH] Error out when reaching max_restarts 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 | 6 +++ .../bin/varnishtest/tests/b00019.vtc | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 varnish-cache/bin/varnishtest/tests/b00019.vtc diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 1bc73f1c..a299a6e0 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -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 index 00000000..2501acbe --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/b00019.vtc @@ -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 -- 2.39.5