Skip to content

Commit

Permalink
builtin: Retry failed 304s by default
Browse files Browse the repository at this point in the history
Named after vcl_backend_refresh from varnishcache#3994.
  • Loading branch information
dridi committed Jun 18, 2024
1 parent b0d5920 commit 2c12ab4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
9 changes: 9 additions & 0 deletions bin/varnishd/builtin.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,18 @@ sub vcl_backend_error {
}

sub vcl_builtin_backend_error {
call vcl_refresh_error;
call vcl_beresp_error;
}

sub vcl_refresh_error {
if (beresp.was_304) {
unset bereq.http.If-Modified-Since;
unset bereq.http.If-None-Match;
return (retry(fetch));
}
}

sub vcl_beresp_error {
set beresp.http.Content-Type = "text/html; charset=utf-8";
set beresp.http.Retry-After = "5";
Expand Down
7 changes: 0 additions & 7 deletions bin/varnishtest/tests/c00129.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ varnish v1 -vcl+backend {
set beresp.grace = 0s;
set beresp.keep = 10s;
}
sub vcl_backend_error {
if (beresp.was_304) {
unset bereq.http.If-Modified-Since;
unset bereq.http.If-None-Match;
return (retry(fetch));
}
}
sub vcl_deliver {
set resp.http.obj-hits = obj.hits;
}
Expand Down
4 changes: 4 additions & 0 deletions doc/sphinx/reference/vcl_step.rst
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ circumstances, be cautious with putting private information there. If
you really must, then you need to explicitly set ``beresp.ttl`` to
zero in ``vcl_backend_error``.

If a conditional fetch failed to process a 304 response and transitioned
to ``vcl_backend_error``, the backend request is retried for a regular
fetch within the same transaction.

The `vcl_backend_error` subroutine may terminate with calling ``return()``
with one of the following keywords:

Expand Down
3 changes: 2 additions & 1 deletion doc/sphinx/reference/vcl_var.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,8 @@ beresp.was_304

When ``true`` this indicates that we got a 304 response
to our conditional fetch from the backend and turned
that into ``beresp.status = 200``
that into ``beresp.status = 200``, unless the refresh
attempt failed.


obj
Expand Down

0 comments on commit 2c12ab4

Please sign in to comment.