[master] 3ffb28c8b backend_probe: Honor the expect_close attribute

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


commit 3ffb28c8b8b7eea6dcf6a6050e211fd64ee1d20e
Author: Walid Boudebouda <walid.boudebouda at gmail.com>
Date:   Mon Jan 16 17:01:13 2023 +0100

    backend_probe: Honor the expect_close attribute
    
    Considering that both Varnish and the backend should normally react to
    the `Connection: close` header added by default, and considering how the
    probe code is structured, the least intrusive approach is to tolerate a
    timeout when we don't expect the backend to actively close the
    connection.

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index d38a51b72..e4589dd37 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -357,8 +357,11 @@ vbp_poke(struct vbp_target *vt)
 		}
 		i = poll(pfd, 1, tmo);
 		if (i <= 0) {
-			if (!i)
+			if (!i) {
+				if (!vt->exp_close)
+					break;
 				errno = ETIMEDOUT;
+			}
 			bprintf(vt->resp_buf, "Poll error %d (%s)",
 			    errno, VAS_errtxt(errno));
 			i = -1;
diff --git a/bin/varnishtest/tests/c00113.vtc b/bin/varnishtest/tests/c00113.vtc
index 190d271e5..978eb8a88 100644
--- a/bin/varnishtest/tests/c00113.vtc
+++ b/bin/varnishtest/tests/c00113.vtc
@@ -10,7 +10,7 @@ varnish v1 -vcl+backend {
 	probe default {
 		.window = 1;
 		.threshold = 1;
-		.timeout = 1s;
+		.timeout = 0.1s;
 		.interval = 0.1s;
 		.expect_close = true;
 	}
@@ -20,10 +20,13 @@ varnish v2 -vcl+backend {
 	probe default {
 		.window = 1;
 		.threshold = 1;
-		.timeout = 1s;
+		.timeout = 0.1s;
 		.interval = 0.1s;
 		.expect_close = false;
 	}
 } -start
 
-# expect_close has no effect yet
+delay 0.5
+
+varnish v1 -cliexpect sick backend.list
+varnish v2 -cliexpect healthy backend.list
diff --git a/doc/sphinx/reference/vcl-probe.rst b/doc/sphinx/reference/vcl-probe.rst
index bb92be1bd..d53d2e265 100644
--- a/doc/sphinx/reference/vcl-probe.rst
+++ b/doc/sphinx/reference/vcl-probe.rst
@@ -104,6 +104,10 @@ Accepts ``true`` or ``false``, defaults to ``true``::
 
     .expect_close = false;
 
+Warning: when the backend does not close the connection,
+setting ``expect_close`` to ``false`` makes probe tasks wait until
+they time out before inspecting the response.
+
 Attribute ``.timeout``
 ----------------------
 


More information about the varnish-commit mailing list