[master] 7078d783f vcc_backend: Add an expect_close attribute to probes

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Feb 8 13:40:10 UTC 2023


commit 7078d783f1e138a1b1d507b9b3c965fc0b79890a
Author: Walid Boudebouda <walid.boudebouda at gmail.com>
Date:   Fri Jan 13 12:15:09 2023 +0100

    vcc_backend: Add an expect_close attribute to probes
    
    Despite adding a `Connection: close` header by default to probe
    requests, Varnish does not actively close the connection as it should.
    This new attribute will allow to tolerate backends that equally don't
    honor this header, and it is true by default to match the current
    behavior.

diff --git a/bin/varnishtest/tests/c00113.vtc b/bin/varnishtest/tests/c00113.vtc
new file mode 100644
index 000000000..190d271e5
--- /dev/null
+++ b/bin/varnishtest/tests/c00113.vtc
@@ -0,0 +1,29 @@
+varnishtest "probe expect close"
+
+server s0 {
+	rxreq
+	txresp
+	expect_close
+} -dispatch
+
+varnish v1 -vcl+backend {
+	probe default {
+		.window = 1;
+		.threshold = 1;
+		.timeout = 1s;
+		.interval = 0.1s;
+		.expect_close = true;
+	}
+} -start
+
+varnish v2 -vcl+backend {
+	probe default {
+		.window = 1;
+		.threshold = 1;
+		.timeout = 1s;
+		.interval = 0.1s;
+		.expect_close = false;
+	}
+} -start
+
+# expect_close has no effect yet
diff --git a/bin/varnishtest/tests/v00005.vtc b/bin/varnishtest/tests/v00005.vtc
index 4e28d5388..9c5a6f447 100644
--- a/bin/varnishtest/tests/v00005.vtc
+++ b/bin/varnishtest/tests/v00005.vtc
@@ -32,6 +32,27 @@ varnish v1 -vcl {
 	}
 }
 
+# Check expect_close definition
+varnish v1 -errvcl {Expected "true" or "false"} {
+	backend b1 {
+		.host = "${localhost}";
+		.probe = {
+			.url = "/";
+			.expect_close = faux;
+		}
+	}
+}
+
+varnish v1 -errvcl {Expected "true" or "false"} {
+	backend b1 {
+		.host = "${localhost}";
+		.probe = {
+			.url = "/";
+			.expect_close = 1;
+		}
+	}
+}
+
 # Check redefinition
 varnish v1 -errvcl {Probe request redefinition at:} {
 	backend b1 {
diff --git a/doc/sphinx/reference/vcl-probe.rst b/doc/sphinx/reference/vcl-probe.rst
index 25eeb5aa1..bb92be1bd 100644
--- a/doc/sphinx/reference/vcl-probe.rst
+++ b/doc/sphinx/reference/vcl-probe.rst
@@ -95,6 +95,15 @@ The expected HTTP status, defaults to ``200``::
 
     .expected_response = 418;
 
+Attribute ``.expect_close``
+---------------------------
+
+Whether or not to expect the backend to close the underlying connection.
+
+Accepts ``true`` or ``false``, defaults to ``true``::
+
+    .expect_close = false;
+
 Attribute ``.timeout``
 ----------------------
 
diff --git a/include/vrt.h b/include/vrt.h
index e9ca4f087..8242c63ef 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -60,6 +60,7 @@
  * NEXT (2023-03-15)
  *	VXID is 64 bit
  *	[cache.h] http_GetRange() changed
+ *	exp_close added to struct vrt_backend_probe
  * 16.0 (2022-09-15)
  *	VMOD C-prototypes moved into JSON
  *	VRT_AddVDP() deprecated
@@ -589,7 +590,8 @@ struct vrt_backend {
 	unsigned			exp_status;		\
 	unsigned			window;			\
 	unsigned			threshold;		\
-	unsigned			initial;
+	unsigned			initial;		\
+	unsigned			exp_close;
 
 #define VRT_BACKEND_PROBE_HANDLE()		\
 	do {					\
@@ -599,6 +601,7 @@ struct vrt_backend {
 		DN(window);			\
 		DN(threshold);			\
 		DN(initial);			\
+		DN(exp_close);			\
 	} while (0)
 
 struct vrt_backend_probe {
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index e4ccde185..f9d31ce8c 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -183,7 +183,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep)
 	const struct token *t_field;
 	const struct token *t_did = NULL, *t_window = NULL, *t_threshold = NULL;
 	struct token *t_initial = NULL;
-	unsigned window, threshold, initial, status;
+	unsigned window, threshold, initial, status, exp_close;
 	char buf[32];
 	const char *name;
 	double t;
@@ -197,6 +197,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep)
 	    "?window",
 	    "?threshold",
 	    "?initial",
+	    "?expect_close",
 	    NULL);
 
 	SkipToken(tl, '{');
@@ -216,6 +217,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep)
 	threshold = 0;
 	initial = 0;
 	status = 0;
+	exp_close = 1;
 	while (tl->t->tok != '}') {
 
 		vcc_IsField(tl, &t_field, fs);
@@ -273,6 +275,9 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep)
 			t_threshold = tl->t;
 			threshold = vcc_UintVal(tl);
 			ERRCHK(tl);
+		} else if (vcc_IdIs(t_field, "expect_close")) {
+			exp_close = vcc_BoolVal(tl);
+			ERRCHK(tl);
 		} else {
 			vcc_ErrToken(tl, t_field);
 			vcc_ErrWhere(tl, t_field);
@@ -321,6 +326,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep)
 		Fh(tl, 0, "\t.initial = ~0U,\n");
 	if (status > 0)
 		Fh(tl, 0, "\t.exp_status = %u,\n", status);
+	Fh(tl, 0, "\t.exp_close = %u,\n", exp_close);
 	Fh(tl, 0, "}};\n");
 	SkipToken(tl, '}');
 }


More information about the varnish-commit mailing list