cant get restart; to fetch and deliver from other backend on HTTP error

Gerald Leier gerald.leier at lixto.com
Thu Aug 27 16:29:13 CEST 2009


hello,

I want to use varnish to "hide" HTTP 50x codes.
As far as i understood this is done in the "sub vcl_fetch"

After setting up 2 servers(one returning the requested page
the other returning 500 errors) i tested a bit but i have
some bug in there i cant get a grip on.

after the first node returns a http 500 error varnish continues with
the second node....here is the part where it stops doing what i want:

.....
10 VCL_return   c restart
10 VCL_call     c recv
10 VCL_return   c pass
10 VCL_call     c pass
10 VCL_return   c pass
11 BackendOpen  b test2 10.10.1.1 51154 10.10.1.50 38080
10 Backend      c 11 www_director test2
11 TxRequest    b POST
11 TxURL        b /testservice
11 TxProtocol   b HTTP/1.1
11 TxHeader     b User-Agent: curl
11 TxHeader     b Host: 10.10.1.1:38080
11 TxHeader     b Accept: */*
11 TxHeader     b Content-Type: text/xml;charset=UTF-8
11 TxHeader     b Content-Length: 326
11 TxHeader     b X-Varnish: 614647428
11 TxHeader     b X-Forwarded-For: 10.21.1.40
	11 BackendClose b test2
	10 VCL_call     c error
	10 VCL_return   c deliver
.....


has anyone a hint on what i am doing wrong?

thanks
 gerald


.....

./varnishd -f ../etc/varnish/testing.vcl -a 10.10.1.1:38080

../etc/varnish/testing.vcl:

backend test1 {
    .host = "10.10.1.50";
    .port = "38080";
}

backend test2 {
    .host = "10.10.1.60";
    .port = "38080";
}

director www_director round-robin {
{ .backend = test1; }
{ .backend = test2; }
}

sub vcl_recv {
# Force lookup if the request is a no-cache request from the client
    if (req.http.Cache-Control ~ "no-cache") { purge_url(req.url); }
    if (req.restarts == 0) {
            set req.backend = www_director;
    } else {
            set req.backend = www_director;
    }
    if (req.request != "GET" && req.request != "HEAD") {
    /* We only deal with GET and HEAD by default */
             return (pass);
    }
    if (req.http.Authorization || req.http.Cookie) {
    /* Not cacheable by default */
             return (pass);
    }
    # set an artificial header to pass on the true client IP address
    remove req.http.X-Varnish-Client-IP;
    set    req.http.X-Varnish-Client-IP = client.ip;
}

sub vcl_fetch {
    if (obj.status == 500 || obj.status == 503 || obj.status == 504) {
            restart;
    }
}

sub vcl_deliver {
    # hide existence of this proxy server
    remove resp.http.X-Varnish;
    remove resp.http.Via;
    deliver;
}
------------------------------------------------------------------------

log:
------------------------------------------------------------------------
10 SessionOpen  c 10.21.1.40 7984 10.10.1.1:38080
10 ReqStart     c 10.21.1.40 7984 614647428
10 RxRequest    c POST
10 RxURL        c /testservice
10 RxProtocol   c HTTP/1.1
10 RxHeader     c User-Agent: curl
10 RxHeader     c Host: 10.10.1.1:38080
10 RxHeader     c Accept: */*
10 RxHeader     c Content-Type: text/xml;charset=UTF-8
10 RxHeader     c Content-Length: 326
10 VCL_call     c recv
10 VCL_return   c pass
10 VCL_call     c pass
10 VCL_return   c pass
11 BackendOpen  b test1 10.10.1.1 60016 10.10.1.60 38080
10 Backend      c 11 www_director test1
11 TxRequest    b POST
11 TxURL        b /testservice
11 TxProtocol   b HTTP/1.1
11 TxHeader     b User-Agent: curl
11 TxHeader     b Host: 10.10.1.1:38080
11 TxHeader     b Accept: */*
11 TxHeader     b Content-Type: text/xml;charset=UTF-8
11 TxHeader     b Content-Length: 326
11 TxHeader     b X-Varnish: 614647428
11 TxHeader     b X-Forwarded-For: 10.21.1.40
0 CLI          - Rd ping
0 CLI          - Wr 0 200 PONG 1251380397 1.0
0 CLI          - Rd ping
0 CLI          - Wr 0 200 PONG 1251380400 1.0
11 RxProtocol   b HTTP/1.1
11 RxStatus     b 500
11 RxResponse   b Internal Server Error
11 RxHeader     b X-Powered-By: Servlet/2.5
11 RxHeader     b Server: Sun GlassFish Enterprise Server
11 RxHeader     b Content-Type: text/xml;charset="utf-8"
11 RxHeader     b Transfer-Encoding: chunked
11 RxHeader     b Date: Thu, 27 Aug 2009 13:39:56 GMT
11 RxHeader     b Connection: close
10 ObjProtocol  c HTTP/1.1
10 ObjStatus    c 500
10 ObjResponse  c Internal Server Error
10 ObjHeader    c X-Powered-By: Servlet/2.5
10 ObjHeader    c Server: Sun GlassFish Enterprise Server
10 ObjHeader    c Content-Type: text/xml;charset="utf-8"
10 ObjHeader    c Date: Thu, 27 Aug 2009 13:39:56 GMT
11 BackendClose b test1
10 TTL          c 614647428 RFC 120 1251380396 0 0 0 0
10 VCL_call     c fetch
10 VCL_return   c restart
10 VCL_call     c recv
10 VCL_return   c pass
10 VCL_call     c pass
10 VCL_return   c pass
11 BackendOpen  b test2 10.10.1.1 51154 10.10.1.50 38080
10 Backend      c 11 www_director test2
11 TxRequest    b POST
11 TxURL        b /testservice
11 TxProtocol   b HTTP/1.1
11 TxHeader     b User-Agent: curl
11 TxHeader     b Host: 10.10.1.1:38080
11 TxHeader     b Accept: */*
11 TxHeader     b Content-Type: text/xml;charset=UTF-8
11 TxHeader     b Content-Length: 326
11 TxHeader     b X-Varnish: 614647428
11 TxHeader     b X-Forwarded-For: 10.21.1.40
11 BackendClose b test2
10 VCL_call     c error
10 VCL_return   c deliver
10 Length       c 465
10 VCL_call     c deliver
10 VCL_return   c deliver
10 TxProtocol   c HTTP/1.1
10 TxStatus     c 503
10 TxResponse   c Service Unavailable
10 TxHeader     c Server: Varnish
10 TxHeader     c Retry-After: 0
10 TxHeader     c Content-Type: text/html; charset=utf-8
10 TxHeader     c Content-Length: 465
10 TxHeader     c Date: Thu, 27 Aug 2009 13:40:01 GMT
10 TxHeader     c Age: 5
10 TxHeader     c Connection: close
10 ReqEnd       c 614647428 1251380396.585108042 1251380401.618464947
0.000111103 5.033315897 0.000041008
10 SessionClose c error



More information about the varnish-misc mailing list