[master] 245b743 Both a label and its VCL must be WARM

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Sep 19 20:37:07 UTC 2017


commit 245b74334f6d7b3d107c262cdeaf43ce94c7253c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Sep 19 20:11:38 2017 +0200

    Both a label and its VCL must be WARM
    
    Otherwise the VCL poker will eventually cool down the underlying VCL.
    
    Fixes #2432

diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index 39cbc64..27fd56a 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -101,6 +101,8 @@ static VTAILQ_HEAD(, vmodfile)	vmodhead = VTAILQ_HEAD_INITIALIZER(vmodhead);
 static struct vclprog		*active_vcl;
 static struct vev *e_poker;
 
+static int mgt_vcl_setstate(struct cli *, struct vclprog *, const char *);
+
 /*--------------------------------------------------------------------*/
 
 static struct vclprog *
@@ -187,6 +189,8 @@ mgt_vcl_dep_add(struct vclprog *vp_from, struct vclprog *vp_to)
 	vd->to = vp_to;
 	VTAILQ_INSERT_TAIL(&vp_to->dto, vd, lto);
 	vp_to->nto++;
+	assert(vp_to->state == VCL_STATE_WARM ||	/* vcl.label ... */
+	    vp_to->state == VCL_STATE_LABEL);		/* return(vcl(...)) */
 }
 
 static void
@@ -197,6 +201,12 @@ mgt_vcl_dep_del(struct vcldep *vd)
 	VTAILQ_REMOVE(&vd->from->dfrom, vd, lfrom);
 	VTAILQ_REMOVE(&vd->to->dto, vd, lto);
 	vd->to->nto--;
+	if (vd->to->nto == 0 && vd->to->state == VCL_STATE_WARM) {
+		vd->to->state = VCL_STATE_AUTO;
+		AZ(vd->to->go_cold);
+		(void)mgt_vcl_setstate(NULL, vd->to, VCL_STATE_AUTO);
+		AN(vd->to->go_cold);
+	}
 	FREE_OBJ(vd);
 }
 
@@ -834,10 +844,9 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)
 		vpl = mgt_vcl_add(av[2], VCL_STATE_LABEL);
 	}
 	AN(vpl);
-	mgt_vcl_dep_add(vpl, vpt);
 	vpl->warm = 1;
-	if (vpt->state == VCL_STATE_COLD)
-		vpt->state = VCL_STATE_AUTO;
+	vpt->state = VCL_STATE_WARM;
+	mgt_vcl_dep_add(vpl, vpt);
 	(void)mgt_vcl_setstate(cli, vpt, VCL_STATE_WARM);
 	if (!MCH_Running())
 		return;
diff --git a/bin/varnishtest/tests/r02432.vtc b/bin/varnishtest/tests/r02432.vtc
new file mode 100644
index 0000000..97b5d30
--- /dev/null
+++ b/bin/varnishtest/tests/r02432.vtc
@@ -0,0 +1,29 @@
+varnishtest "label going cold"
+
+server s1 { } -start
+
+varnish v1 -cliok "param.set vcl_cooldown 1"
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		return (synth(200));
+	}
+} -start
+
+varnish v1 -cliok "vcl.label label1 vcl1"
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		return (vcl(label1));
+	}
+}
+
+# let the VCL poker trigger enough times to get
+# an occasion to update vcl1's state
+delay 3
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run


More information about the varnish-commit mailing list