Commit 75ea7f62 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent 119056c4
......@@ -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)
/*--------------------------------------------------------------------*/
......
......@@ -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)
......
......@@ -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);
......
......@@ -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;
......
......@@ -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)
/*--------------------------------------------------------------------*/
......
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
......@@ -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)`.
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment