We use varnish 4 for caching and processing ESI. For ESI requests that return a 5XX backend error, we return an empty synthetic response.
That empty response should be cached for a few seconds, because currently every subsequent request to the same ESI hits the backend again. That causes heavy load on our backends, whenever the cause of the 5XX response is an expensive one.
sub vcl_backend_error {
....
if (isAnESI && beresp.status >= 500 && beresp.status <= 599) {
synthetic({""});
return(deliver);
}
}
We tried to add a Retry-After
header on the response, but that doesn't do the trick.
set beresp.http.Retry-After = "5";