[5.1] 99b1a62 Check backend existence when reading proxy_header

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Apr 10 13:59:06 CEST 2017


commit 99b1a625c400ce0751967f1a0b7552d60de9c144
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Mar 28 10:43:56 2017 +0200

    Check backend existence when reading proxy_header
    
    A probe may still be running when its backend is deleted. In that case
    it needs to read the proxy_header field under the lock and give up if
    the backend was already gone.
    
    Not sure how to write a test case for this one.
    
    Fixes #2278

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index 4c18854..3d5bc15 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -267,7 +267,7 @@ vbp_write_proxy_v1(struct vbp_target *vt, int *sock)
 static void
 vbp_poke(struct vbp_target *vt)
 {
-	int s, tmo, i;
+	int s, tmo, i, proxy_header;
 	double t_start, t_now, t_end;
 	unsigned rlen, resp;
 	char buf[8192], *p;
@@ -299,12 +299,22 @@ vbp_poke(struct vbp_target *vt)
 		return;
 	}
 
+	Lck_Lock(&vbp_mtx);
+	if (vt->backend != NULL)
+		proxy_header = vt->backend->proxy_header;
+	else
+		proxy_header = -1;
+	Lck_Unlock(&vbp_mtx);
+
+	if (proxy_header < 0)
+		return;
+
 	/* Send the PROXY header */
-	assert(vt->backend->proxy_header <= 2);
-	if (vt->backend->proxy_header == 1) {
+	assert(proxy_header <= 2);
+	if (proxy_header == 1) {
 		if (vbp_write_proxy_v1(vt, &s) != 0)
 			return;
-	} else if (vt->backend->proxy_header == 2 &&
+	} else if (proxy_header == 2 &&
 	    vbp_write(vt, &s, vbp_proxy_local, sizeof vbp_proxy_local) != 0)
 		return;
 



More information about the varnish-commit mailing list