Hi,

As Dridi said, what you are looking for is exactly vmod_stale, but I wanted
to point out that part:

> We have a backend that actually proxies different services

In that case, it might be good to actually have a Varnish backend for each
type of backend behind the proxies. The backend definition would be exactly
the same, but the probe definitions would be different, with a specific
URL/host. this way, Varnish would be aware of who is actually unhealthy and
you don't have to deal with the stale thing.

If you need an open-source approach, I reckon the best you can do is
restart with a zero TTL if you detect a bad response. It does have a couple
of race conditions baked-in that vmod_stale sidesteps, but that's usually
good enough:

sub vcl_recv {
    # be hopeful that the backend will send us something good, ignore grace
    if (req.restarts == 0) {
        set req.grace = 0s;
    }
}

sub vcl_deliver {
    # welp, that didn't go well, try again without limiting the grace
    if (req.restarts == 0 && resp.status >= 500) {
        set req.ttl = 10y;
        return (restart);
    }
}


Main issue is that you restart, so you are going to spend a lil bit more
time/resources processing the request, and the object in cache may have
expired by the time you realize you need it.

Hope that helps,
-- 
Guillaume Quintard
_______________________________________________
varnish-misc mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

Reply via email to