Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Varnish won't recognize req.grace variable

I have a fresh install of Slackware 64 14bit, and looking through Varnish installation documentation I have all the dependencies installed and compiled varnish with no error (make check passes all tests)

Yet, when I try to run varnish using

varnishd -f /etc/varnish/user.vcl -s malloc,4G -T 127.0.0.1:2000

I get

Message from VCC-compiler:
Unknown variable 'req.grace'
At: ('input' Line 17 Pos 9)
    set req.grace = 15s;
--------#########-------

Running VCC-compiler failed, exit 1

VCL compilation failed

My very simple /etc/varnish/ucer.vcl file looks like this:

vcl 4.0;

# set default backend if no server cluster specified
backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .probe = {
        .url = "/";
        .timeout = 34ms;
        .interval = 1s;
        .window = 10;
        .threshold = 8;
    }
}

sub vcl_recv {
    set req.grace = 15s;
}

sub vcl_fetch {
    set beresp.grace = 30m;
}

The variable names are identical to this example.

varnishd -V returns

varnishd (varnish-4.0.0 revision 2acedeb)

By removing both sub vcl_recv and sub vcl_fetch (using only backend default) varnish works fine and I can see it's headers, but I need to edit the VCL file.

Any ideas?

like image 593
Renato Siqueira Massaro Avatar asked Apr 25 '14 05:04

Renato Siqueira Massaro


2 Answers

You are using Varnish 4.0.0, which needs updating from the 3.0 format your VCL code is based on.

req.grace is gone (you usually don't need it) and vcl_fetch is now called vcl_backend_response.

See the upgrade documentation: https://www.varnish-cache.org/docs/trunk/whats-new/upgrading.html

like image 109
lkarsten Avatar answered Sep 22 '22 05:09

lkarsten


For reference, it is possible to handle properly the grace feature, following what is said in this blog post:

(copy/paste of the code, for more details refer to the blog)

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # normal hit
        return (deliver);
    }
    # We have no fresh fish. Lets look at the stale ones.
    if (std.healthy(req.backend_hint)) {
        # Backend is healthy. Limit age to 10s.
        if (obj.ttl + 10s > 0s) {
            set req.http.grace = "normal(limited)";
            return (deliver);
        } else {
            # No candidate for grace. Fetch a fresh object.
            return(fetch);
        }
    } else {
        # backend is sick - use full grace
        if (obj.ttl + obj.grace > 0s) {
            set req.http.grace = "full";
            return (deliver);
        } else {
            # no graced object.
            return (fetch);
        }
    }
}

HTH

like image 26
zmo Avatar answered Sep 22 '22 05:09

zmo