Mailing List Archive

[master] 75ea7f62b vcl: All bereq timeouts can now be unset
commit 75ea7f62bcd5add6d0b934a85d33105e04e943c7
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Wed Feb 28 19:01:19 2024 +0100

vcl: All bereq timeouts can now be unset

Unlike session timeouts, they were not falling back to their parameter
counterparts from NAN. Since NAN is not allowed in VCL, they now behave
like session timeouts, returning their value or falling back to the
parameter when unset.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7d6b68457..10fab7e8d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -446,6 +446,9 @@ struct busyobj {
const char *client_identity;
};

+#define BUSYOBJ_TMO(bo, pfx, tmo) \
+ (isnan((bo)->tmo) ? cache_param->pfx##tmo : (bo)->tmo)
+

/*--------------------------------------------------------------------*/

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 02bb82996..935527015 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -99,9 +99,9 @@ VBE_Connect_Error(struct VSC_vbe *vsc, int err)
do { \
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); \
dst = bo->tmx; \
- if (dst == 0.0 && be->tmx >= 0.0) \
+ if (isnan(dst) && be->tmx >= 0.0) \
dst = be->tmx; \
- if (dst == 0.0) \
+ if (isnan(dst)) \
dst = cache_param->tmx; \
} while (0)

diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 9a5fe36d1..593bdfe43 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -142,6 +142,9 @@ VBO_GetBusyObj(const struct worker *wrk, const struct req *req)
VCL_Ref(bo->vcl);

bo->t_first = bo->t_prev = NAN;
+ bo->connect_timeout = NAN;
+ bo->first_byte_timeout = NAN;
+ bo->between_bytes_timeout = NAN;

memcpy(bo->digest, req->digest, sizeof bo->digest);

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index f49de59cf..f37183582 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -332,6 +332,9 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo)
bo->was_304 = 0;
bo->err_code = 0;
bo->err_reason = NULL;
+ bo->connect_timeout = NAN;
+ bo->first_byte_timeout = NAN;
+ bo->between_bytes_timeout = NAN;
if (bo->htc != NULL)
bo->htc->doclose = SC_NULL;

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index e509aea4b..5f5cc75fe 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -387,26 +387,14 @@ VRT_l_client_identity(VRT_CTX, const char *str, VCL_STRANDS s)

/*--------------------------------------------------------------------*/

-#define BEREQ_TIMEOUT_UNSET0(which)
-
-#define BEREQ_TIMEOUT_UNSET1(which) \
-VCL_VOID \
-VRT_u_bereq_##which(VRT_CTX) \
-{ \
- \
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
- CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \
- ctx->bo->which = NAN; \
-}
-
-#define BEREQ_TIMEOUT(which, unset) \
+#define BEREQ_TIMEOUT(prefix, which) \
VCL_VOID \
VRT_l_bereq_##which(VRT_CTX, VCL_DURATION num) \
{ \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \
- ctx->bo->which = (num > 0.0 ? num : 0.0); \
+ ctx->bo->which = num; \
} \
\
VCL_DURATION \
@@ -415,15 +403,22 @@ VRT_r_bereq_##which(VRT_CTX) \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \
- return (ctx->bo->which); \
+ return (BUSYOBJ_TMO(ctx->bo, prefix, which)); \
} \
\
-BEREQ_TIMEOUT_UNSET##unset(which)
+VCL_VOID \
+VRT_u_bereq_##which(VRT_CTX) \
+{ \
+ \
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \
+ ctx->bo->which = NAN; \
+}

-BEREQ_TIMEOUT(connect_timeout, 0)
-BEREQ_TIMEOUT(first_byte_timeout, 0)
-BEREQ_TIMEOUT(between_bytes_timeout, 0)
-BEREQ_TIMEOUT(task_deadline, 1)
+BEREQ_TIMEOUT(, connect_timeout)
+BEREQ_TIMEOUT(, first_byte_timeout)
+BEREQ_TIMEOUT(, between_bytes_timeout)
+BEREQ_TIMEOUT(pipe_, task_deadline)


/*--------------------------------------------------------------------*/
diff --git a/bin/varnishtest/tests/v00070.vtc b/bin/varnishtest/tests/v00070.vtc
new file mode 100644
index 000000000..57aa2c235
--- /dev/null
+++ b/bin/varnishtest/tests/v00070.vtc
@@ -0,0 +1,52 @@
+varnishtest "Unset bereq timeouts"
+
+varnish v1 -cliok "param.set connect_timeout 42"
+varnish v1 -cliok "param.set first_byte_timeout 42"
+varnish v1 -cliok "param.set between_bytes_timeout 42"
+
+varnish v1 -vcl {
+ backend be none;
+
+ sub vcl_backend_fetch {
+ return (error(200));
+ }
+
+ sub vcl_backend_error {
+ set beresp.http.def_connect_timeout = bereq.connect_timeout;
+ set beresp.http.def_first_byte_timeout = bereq.first_byte_timeout;
+ set beresp.http.def_between_bytes_timeout = bereq.between_bytes_timeout;
+
+ set bereq.connect_timeout = 0s;
+ set bereq.first_byte_timeout = 0s;
+ set bereq.between_bytes_timeout = 0s;
+
+ set beresp.http.set_connect_timeout = bereq.connect_timeout;
+ set beresp.http.set_first_byte_timeout = bereq.first_byte_timeout;
+ set beresp.http.set_between_bytes_timeout = bereq.between_bytes_timeout;
+
+ unset bereq.connect_timeout;
+ unset bereq.first_byte_timeout;
+ unset bereq.between_bytes_timeout;
+
+ set beresp.http.unset_connect_timeout = bereq.connect_timeout;
+ set beresp.http.unset_first_byte_timeout = bereq.first_byte_timeout;
+ set beresp.http.unset_between_bytes_timeout = bereq.between_bytes_timeout;
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+
+ expect resp.http.def_connect_timeout == 42.000
+ expect resp.http.def_first_byte_timeout == 42.000
+ expect resp.http.def_between_bytes_timeout == 42.000
+
+ expect resp.http.set_connect_timeout == 0.000
+ expect resp.http.set_first_byte_timeout == 0.000
+ expect resp.http.set_between_bytes_timeout == 0.000
+
+ expect resp.http.unset_connect_timeout == 42.000
+ expect resp.http.unset_first_byte_timeout == 42.000
+ expect resp.http.unset_between_bytes_timeout == 42.000
+} -run
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 3be25d54e..469721164 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -652,6 +652,8 @@ bereq.between_bytes_timeout

Writable from: backend

+ Unsetable from: vcl_pipe, backend
+
Default: ``.between_bytes_timeout`` attribute from the
:ref:`backend_definition`, which defaults to the
``between_bytes_timeout`` parameter, see :ref:`varnishd(1)`.
@@ -682,6 +684,8 @@ bereq.connect_timeout

Writable from: vcl_pipe, backend

+ Unsetable from: vcl_pipe, backend
+
Default: ``.connect_timeout`` attribute from the
:ref:`backend_definition`, which defaults to the
``connect_timeout`` parameter, see :ref:`varnishd(1)`.
@@ -700,6 +704,8 @@ bereq.first_byte_timeout

Writable from: backend

+ Unsetable from: vcl_pipe, backend
+
Default: ``.first_byte_timeout`` attribute from the
:ref:`backend_definition`, which defaults to the
``first_byte_timeout`` parameter, see :ref:`varnishd(1)`.
diff --git a/include/vrt.h b/include/vrt.h
index a9c347aab..5599ac7c9 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -66,6 +66,12 @@
* VRT_u_sess_timeout_linger() added
* (struct vrt_backend).*_timeout must be initialized to a negative value
* VRT_BACKEND_INIT() helper macro added
+ * VRT_l_bereq_task_deadline() added
+ * VRT_r_bereq_task_deadline() added
+ * VRT_u_bereq_task_deadline() added
+ * VRT_u_bereq_between_bytes_timeout() added
+ * VRT_u_bereq_connect_timeout() added
+ * VRT_u_bereq_first_byte_timeout() added
* 18.1 (2023-12-05)
* vbf_objiterate() implementation changed #4013
* 18.0 (2023-09-15)
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit