[master] 764a86caf vcl: New bereq.retry_connect variable
Walid Boudebouda
walid.boudebouda at gmail.com
Mon Nov 24 14:26:04 UTC 2025
commit 764a86cafb6f8f685d5ae9421f22fe157319c411
Author: Walid Boudebouda <walid.boudebouda at gmail.com>
Date: Fri Nov 21 13:05:36 2025 +0100
vcl: New bereq.retry_connect variable
Controls whether Varnish will make a second attempt to connect to the
backend if recycling an existing connection failed. This allows users
to prevent undesired retries of potentially non-idempotent requests
on backend connection failures, and provides a finer grained control.
Fixes: #4413
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index fc5b9cf93..c86fa83f7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -455,6 +455,7 @@ struct busyobj {
#define BUSYOBJ_TMO(bo, pfx, tmo) \
(isnan((bo)->tmo) ? cache_param->pfx##tmo : (bo)->tmo)
+extern const char *retry_disabled;
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 0bfd34637..8f185ce4f 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -315,7 +315,7 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo)
assert(bo->fetch_objcore->boc->state <= BOS_REQ_DONE);
- if (bo->no_retry != NULL) {
+ if (bo->no_retry != NULL && bo->no_retry != retry_disabled) {
VSLb(bo->vsl, SLT_Error,
"Retry not possible, %s", bo->no_retry);
return (F_STP_FAIL);
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index cc99f0153..a6d049764 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -48,6 +48,7 @@
#define VRT_TMO(tmo) (isinf(tmo) ? VRT_DECIMAL_MAX : tmo)
static char vrt_hostname[255] = "";
+const char *retry_disabled = "disabled from VCL";
/*--------------------------------------------------------------------
* VRT variables relating to first line of HTTP/1.1 req/resp
@@ -737,6 +738,28 @@ VRT_r_bereq_retries(VRT_CTX)
return (ctx->bo->retries);
}
+VCL_VOID
+VRT_l_bereq_retry_connect(VRT_CTX, VCL_BOOL b)
+{
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+
+ if (!b && ctx->bo->no_retry == NULL)
+ ctx->bo->no_retry = retry_disabled;
+ else if (b && ctx->bo->no_retry == retry_disabled)
+ ctx->bo->no_retry = NULL;
+}
+
+VCL_BOOL
+VRT_r_bereq_retry_connect(VRT_CTX)
+{
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+ return (ctx->bo->no_retry == NULL);
+}
+
/*--------------------------------------------------------------------*/
VCL_STRING
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 52cff63da..1c0d8e9ef 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -908,6 +908,27 @@ bereq.retries
A count of how many times this request has been retried.
+.. _bereq.retry_connect:
+
+bereq.retry_connect
+
+ Type: BOOL
+
+ Readable from: backend
+
+ Writable from: backend
+
+ Default: ``true``.
+ Controls whether Varnish will make a second attempt to connect to the
+ backend if a first connection reuse attempt failed. Setting to ``false``
+ means that no retries will be made. However, setting this to ``true``
+ does not guarantee that a retry will always be attempted, as there are
+ other factors involved in the decision (ex: a request body not being
+ cached).
+ Note that this only controls automatic retries due to connection
+ failures, and does not affect retries initiated from VCL using
+ ``return(retry);``.
+
.. _bereq.task_deadline:
More information about the varnish-commit
mailing list