Mailing List Archive

[master] 119056c4d vcc_backend: Initialize undefined timeouts with -1
commit 119056c4d9319155c6c6c2148519d2e8d81d5f76
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Wed Feb 28 17:35:32 2024 +0100

vcc_backend: Initialize undefined timeouts with -1

We can't use NAN in VGC code today, so in order to convey the lack of
timeout setting in a backend definition, only a negative value makes
sense since zero will eventually mean zero instead of undefined.

This is an implicit breakage of the VRT ABI for the meaning of struct
vrt_backend.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 7b273c5b7..02bb82996 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -99,7 +99,7 @@ VBE_Connect_Error(struct VSC_vbe *vsc, int err)
do { \
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); \
dst = bo->tmx; \
- if (dst == 0.0) \
+ if (dst == 0.0 && be->tmx >= 0.0) \
dst = be->tmx; \
if (dst == 0.0) \
dst = cache_param->tmx; \
diff --git a/include/vrt.h b/include/vrt.h
index 8bbdf8186..a9c347aab 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -64,6 +64,8 @@
* VRT_u_sess_send_timeout() added
* VRT_u_sess_timeout_idle() added
* VRT_u_sess_timeout_linger() added
+ * (struct vrt_backend).*_timeout must be initialized to a negative value
+ * VRT_BACKEND_INIT() helper macro added
* 18.1 (2023-12-05)
* vbf_objiterate() implementation changed #4013
* 18.0 (2023-09-15)
@@ -582,6 +584,14 @@ struct vrt_endpoint {
unsigned max_connections; \
unsigned proxy_header;

+#define VRT_BACKEND_INIT(be) \
+ do { \
+ INIT_OBJ(be, VRT_BACKEND_MAGIC); \
+ (be)->connect_timeout = -1.0; \
+ (be)->first_byte_timeout = -1.0; \
+ (be)->between_bytes_timeout = -1.0; \
+ } while(0)
+
#define VRT_BACKEND_HANDLE() \
do { \
DA(vcl_name); \
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index c199e2d36..8d40c472f 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -32,6 +32,7 @@

#include "config.h"

+#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -381,9 +382,11 @@ vcc_ParseHostDef(struct vcc *tl, struct symbol *sym,
struct inifin *ifp;
struct vsb *vsb1;
struct symbol *via = NULL;
+ vtim_dur connect_timeout = NAN;
+ vtim_dur first_byte_timeout = NAN;
+ vtim_dur between_bytes_timeout = NAN;
char *p;
unsigned u;
- double t;

if (tl->t->tok == ID &&
(vcc_IdIs(tl->t, "none") || vcc_IdIs(tl->t, "None"))) {
@@ -480,21 +483,21 @@ vcc_ParseHostDef(struct vcc *tl, struct symbol *sym,
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "connect_timeout")) {
Fb(tl, 0, "\t.connect_timeout = ");
- vcc_Duration(tl, &t);
+ vcc_Duration(tl, &connect_timeout);
ERRCHK(tl);
- Fb(tl, 0, "%g,\n", t);
+ Fb(tl, 0, "%g,\n", connect_timeout);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "first_byte_timeout")) {
Fb(tl, 0, "\t.first_byte_timeout = ");
- vcc_Duration(tl, &t);
+ vcc_Duration(tl, &first_byte_timeout);
ERRCHK(tl);
- Fb(tl, 0, "%g,\n", t);
+ Fb(tl, 0, "%g,\n", first_byte_timeout);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "between_bytes_timeout")) {
Fb(tl, 0, "\t.between_bytes_timeout = ");
- vcc_Duration(tl, &t);
+ vcc_Duration(tl, &between_bytes_timeout);
ERRCHK(tl);
- Fb(tl, 0, "%g,\n", t);
+ Fb(tl, 0, "%g,\n", between_bytes_timeout);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "max_connections")) {
u = vcc_UintVal(tl);
@@ -581,6 +584,13 @@ vcc_ParseHostDef(struct vcc *tl, struct symbol *sym,
free(fs);
ERRCHK(tl);

+ if (isnan(connect_timeout))
+ Fb(tl, 0, "\t.connect_timeout = -1.0,\n");
+ if (isnan(first_byte_timeout))
+ Fb(tl, 0, "\t.first_byte_timeout = -1.0,\n");
+ if (isnan(between_bytes_timeout))
+ Fb(tl, 0, "\t.between_bytes_timeout = -1.0,\n");
+
ExpectErr(tl, '}');

if (t_host == NULL && t_path == NULL) {
diff --git a/vmod/vmod_debug_dyn.c b/vmod/vmod_debug_dyn.c
index 4714c436b..6b83299e4 100644
--- a/vmod/vmod_debug_dyn.c
+++ b/vmod/vmod_debug_dyn.c
@@ -75,7 +75,7 @@ dyn_dir_init(VRT_CTX, struct xyzzy_debug_dyn *dyn,
CHECK_OBJ_ORNULL(via, DIRECTOR_MAGIC);

INIT_OBJ(&vep, VRT_ENDPOINT_MAGIC);
- INIT_OBJ(&vrt, VRT_BACKEND_MAGIC);
+ VRT_BACKEND_INIT(&vrt);
vrt.endpoint = &vep;
vrt.vcl_name = dyn->vcl_name;
vrt.hosthdr = addr;
@@ -206,7 +206,7 @@ dyn_uds_init(VRT_CTX, struct xyzzy_debug_dyn_uds *uds, VCL_STRING path)
}

INIT_OBJ(&vep, VRT_ENDPOINT_MAGIC);
- INIT_OBJ(&vrt, VRT_BACKEND_MAGIC);
+ VRT_BACKEND_INIT(&vrt);
vrt.endpoint = &vep;
vep.uds_path = path;
vrt.vcl_name = uds->vcl_name;
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit