[master] 21e653c Use the hash digest as identification instead of the neutered objhead pointer, in order to not have dependency between trouble entry and objhead lifetime.

Poul-Henning Kamp phk at varnish-cache.org
Mon Feb 27 13:42:33 CET 2012


commit 21e653c3a3e0686232646b9f933de72b6536fb50
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 27 12:41:33 2012 +0000

    Use the hash digest as identification instead of the neutered objhead
    pointer, in order to not have dependency between trouble entry and
    objhead lifetime.
    
    Fixes	#1091

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 52f1c38..dcb87dd 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -244,7 +244,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp)
 	unsigned i = 0, retval;
 	unsigned int threshold;
 	struct backend *backend;
-	uintptr_t target;
 	double now;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -276,7 +275,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp)
 		return (1);
 
 	now = sp->t_req;
-	target = (uintptr_t)(sp->req->objcore->objhead);
 
 	old = NULL;
 	retval = 1;
@@ -291,7 +289,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp)
 			break;
 		}
 
-		if (tr->target == target) {
+		if (!memcmp(tr->digest, sp->req->digest, sizeof tr->digest)) {
 			retval = 0;
 			break;
 		}
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index b1688f9..96f0a63 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -97,7 +97,7 @@ struct director {
 struct trouble {
 	unsigned		magic;
 #define TROUBLE_MAGIC		0x4211ab21
-	uintptr_t		target;
+	unsigned char		digest[DIGEST_LEN];
 	double			timeout;
 	VTAILQ_ENTRY(trouble)	list;
 };
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 72fa4dc..2e56666 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -152,7 +152,7 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a)
 
 	ALLOC_OBJ(new, TROUBLE_MAGIC);
 	AN(new);
-	new->target = (uintptr_t)(sp->req->objcore->objhead);
+	memcpy(new->digest, sp->req->digest, sizeof new->digest);
 	new->timeout = sp->t_req + a;
 
 	/* Insert the new item on the list before the first item with a
diff --git a/bin/varnishtest/tests/r01091.vtc b/bin/varnishtest/tests/r01091.vtc
new file mode 100644
index 0000000..9234ffc
--- /dev/null
+++ b/bin/varnishtest/tests/r01091.vtc
@@ -0,0 +1,36 @@
+varnishtest "Test fallback director with saint mode"
+
+server s1 {
+        rxreq
+        txresp -hdr "Foo: 1"
+        accept
+        rxreq
+        txresp -hdr "Foo: 1"
+} -start
+
+server s2 {
+        rxreq
+        txresp -hdr "Foo: 2" -bodylen 1
+} -start
+
+varnish v1 -vcl+backend {
+        director f1 fallback {
+                { .backend = s1; }
+                { .backend = s2; }
+        }
+        sub vcl_recv {
+                set req.backend = f1;
+        }
+        sub vcl_fetch {
+                if(req.restarts < 1) {
+                        set beresp.saintmode = 1h;
+                        return(restart);
+                }
+        }
+} -start
+
+client c1 {
+        txreq
+        rxresp
+        expect resp.http.foo == "2"
+} -run



More information about the varnish-commit mailing list