From a0b6a7e0427cb7efd40d0df987bb0da0a50b4c4f Mon Sep 17 00:00:00 2001 From: Dridi Boukelmoune Date: Tue, 19 Mar 2024 11:05:05 +0100 Subject: [PATCH] builtin: Retry failed 304s by default Named after vcl_backend_refresh from #3994. --- bin/varnishd/builtin.vcl | 7 +++++++ doc/sphinx/reference/vcl_step.rst | 4 ++++ doc/sphinx/reference/vcl_var.rst | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl index 6a0a5baf4bf..fe450081d27 100644 --- a/bin/varnishd/builtin.vcl +++ b/bin/varnishd/builtin.vcl @@ -257,9 +257,16 @@ 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) { + return (retry); + } +} + sub vcl_beresp_error { set beresp.http.Content-Type = "text/html; charset=utf-8"; set beresp.http.Retry-After = "5"; diff --git a/doc/sphinx/reference/vcl_step.rst b/doc/sphinx/reference/vcl_step.rst index ee07f616923..395e9e94bd1 100644 --- a/doc/sphinx/reference/vcl_step.rst +++ b/doc/sphinx/reference/vcl_step.rst @@ -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 transaction is retried as a regular +fetch. + The `vcl_backend_error` subroutine may terminate with calling ``return()`` with one of the following keywords: diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst index 4697211648b..9bebb64be40 100644 --- a/doc/sphinx/reference/vcl_var.rst +++ b/doc/sphinx/reference/vcl_var.rst @@ -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