vcl_fetch not respect previous pass decision

marco at nucleus.it marco at nucleus.it
Thu Nov 20 17:41:03 CET 2014


Hi to all , 
i'm using varnish-3.0.5 and i have a strange behaviour.

The problem is that pass decided in vcl_recv trigger a deliver and not
an hit_for_pass or pass by default if i set beresp.ttl in the vcl_fetch.
Doing deliver, the object is cached and i don't want to cache it ,
wasting memory or disk space used for storage backend.

According to

https://www.varnish-software.com/static/book/VCL_Basics.html

"If you chose to pass the request in an earlier VCL function (e.g.:
vcl_recv), you will still execute the logic of vcl_fetch, but the
object will not enter the cache even if you supply a cache time."

So as i understand a previous pass decision , like in a vcl_recv , must
trigger a pass also in vcl_fetch even if i set a ttl in beresp.ttl .

example with the config in the bottom and not working as documented:
wget -nd -S http://www.mysite.com/robots.txt

   10 RxRequest    c GET
   10 RxURL        c /robots.txt
   10 RxProtocol   c HTTP/1.1
   10 RxHeader     c User-Agent: Wget/1.16 (linux-gnu)
   10 RxHeader     c Accept: */*
   10 RxHeader     c Host: www.mysite.com
   10 RxHeader     c Connection: Keep-Alive
   10 VCL_call     c recv pass
   10 VCL_call     c hash
   10 Hash         c /robots.txt
   10 Hash         c www.mysite.com
   10 VCL_return   c hash
   10 VCL_call     c pass pass
   10 Backend      c 13 mysite mysite
   10 TTL          c 1449425053 RFC 1209600 -1 -1 1416500172 0
   1416500848 1417710448 1209600 10 VCL_call     c fetch
   10 TTL          c 1449425053 VCL 604800 -1 -1 1416500172 -0
   10 TTL          c 1449425053 VCL 604800 86400 -1 1416500172 -0
   10 VCL_return   c deliver


commenting in vcl_fetch section "set beresp.ttl = 1w"
vcl_fetch respects the pass decision decided in vcl_recv but the
problem is that i want set beresp.ttl to me needs and that what
reported in the link maybe is not correct.

    4 RxRequest    c GET
    4 RxURL        c /robots.txt
    4 RxProtocol   c HTTP/1.1
    4 RxHeader     c User-Agent: Wget/1.16 (linux-gnu)
    4 RxHeader     c Accept: */*
    4 RxHeader     c Host: www.mysite.com
    4 RxHeader     c Connection: Keep-Alive
    4 VCL_call     c recv pass
    4 VCL_call     c hash
    4 Hash         c /robots.txt
    4 Hash         c www.mysite.com
    4 VCL_return   c hash
    4 VCL_call     c pass pass
    4 Backend      c 13 mysite mysite
    4 TTL          c 380775699 RFC 1209600 -1 -1 1416500647 0
    1416501323 1417710923 1209600 4 VCL_call     c fetch
    4 TTL          c 380775699 VCL -1 86400 -1 1416500647 -0
    4 TTL          c 380775699 VCL 120 86400 -1 1416500647 -0
    4 VCL_return   c hit_for_pass


Any suggestion ?

###########

sub vcl_recv {
    if (req.http.host ~
"^(?i)(www\.mysite\.com|mysite\.com)$")
{ set req.backend = mysite;

      if (req.url == "/robots.txt"  ) {
      return (pass); 
      }
      return(lookup);
    }
    else {
      #Di default i siti non gestiti dal Varnish 
      error 404 "Not Found";
    }
    if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "TRACE" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
    }
    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);
    }

    return (lookup);
}

sub vcl_fetch {
set beresp.storage = "othersram";
   if (beresp.backend.name ~ "mysite") {
      set beresp.storage = "mysitedisk";
      remove beresp.http.Cache-Control;
      remove beresp.http.Pragma;
      remove beresp.http.Expires;

      set beresp.ttl = 1w;
      set beresp.storage = "mysitedisk";
      set beresp.grace = 1d;
   }
}



More information about the varnish-misc mailing list