Varnish cache server – Guru Meditation 503 …

cachestream

Recently, i face this annoying error with my varnish cache server

Error 503 Service Unavailable
Service Unavailable
Guru Meditation:
XID: 1937610824
Varnish cache server

this issue scared me 🙁 , because everything has been working well with varnish cache server. luckily, i had this issue at the moment i deployed a new feature that will send a big file over http protocol with content type = ‘application/octet-stream’.

from this point, i suspected that varnish cache server has something to do with large file transfer over http. so the question is : how to ignore varnish cache in such case ?

after googling and studying varnish cache, i found that we can do it with a simple rule. this rule returns pipe – AKA : content from back end server directly to client

# bypass export CSV , you can replace your url pattern with /exportlimit/all/
if ( req.url ~ ".*/exportlimit/all/.*" ) {
  set req.http.connection = "close";
   return(pipe);
}

this is where it should be in varnish VCL file (/etc/varnsih/default.vcl or else where you specified)

sub vcl_recv {
    if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
            req.http.X-Forwarded-For + ", " + client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
    }

    if (req.request != "GET" &&
        req.request != "HEAD" &&
        req.request != "PUT" &&
        req.request != "POST" &&
        req.request != "TRACE" &&
        req.request != "OPTIONS" &&
        req.request != "DELETE" &&
        req.request != "PURGE") {
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
    }

     # bypass export CSV
     if ( req.url ~ ".*/exportlimit/all/.*" ) {
       set req.http.connection = "close";
        return(pipe);
     }

    # purge request
    if (req.request == "PURGE") {
        if (!client.ip ~ purge) {
            error 405 "Not allowed.";
        }
        ban("obj.http.X-Purge-Host ~ " + req.http.X-Purge-Host + " && obj.http.X-Purge-URL ~ " + req.http.X-Purge-Regex + " && obj.http.Content-Type ~ " + req.http.X-Purge-Content-Type);
        error 200 "Purged.";
    }

    # switch to admin backend configuration
    if (req.http.cookie ~ "adminhtml=") {
        set req.backend = admin;
    }

remember to restart/reload varnish cache server after having it planted in the VCL file

service varnish restart