Skip to content

Commit 541cd7a

Browse files
committed
builtin: Retry failed 304s by default
Named after vcl_backend_refresh from #3994.
1 parent bdaec65 commit 541cd7a

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

bin/varnishd/builtin.vcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,16 @@ sub vcl_backend_error {
257257
}
258258

259259
sub vcl_builtin_backend_error {
260+
call vcl_refresh_error;
260261
call vcl_beresp_error;
261262
}
262263

264+
sub vcl_refresh_error {
265+
if (beresp.was_304) {
266+
return (retry);
267+
}
268+
}
269+
263270
sub vcl_beresp_error {
264271
set beresp.http.Content-Type = "text/html; charset=utf-8";
265272
set beresp.http.Retry-After = "5";

bin/varnishtest/tests/c00129.vtc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ varnish v1 -vcl+backend {
2828
set beresp.grace = 0s;
2929
set beresp.keep = 10s;
3030
}
31-
sub vcl_backend_error {
32-
if (beresp.was_304) {
33-
return (retry);
34-
}
35-
}
3631
sub vcl_deliver {
3732
set resp.http.obj-hits = obj.hits;
3833
}

doc/sphinx/reference/vcl_step.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ circumstances, be cautious with putting private information there. If
392392
you really must, then you need to explicitly set ``beresp.ttl`` to
393393
zero in ``vcl_backend_error``.
394394

395+
If a conditional fetch failed to process a 304 response and transitioned
396+
to ``vcl_backend_error``, the backend transaction is retried as a regular
397+
fetch.
398+
395399
The `vcl_backend_error` subroutine may terminate with calling ``return()``
396400
with one of the following keywords:
397401

doc/sphinx/reference/vcl_var.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,8 @@ beresp.was_304
13781378

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

13831384

13841385
obj

0 commit comments

Comments
 (0)