[master] 3162873 Don't create backends on cooling VCLs, return NULL

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Dec 4 16:03:22 CET 2015


commit 3162873747e9241383626d9cb501f363f7931b4b
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Dec 4 15:44:44 2015 +0100

    Don't create backends on cooling VCLs, return NULL

diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 17b90f0..0bc73ed 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -130,5 +130,5 @@ struct vbc *VBT_Get(struct tcp_pool *, double tmo, const struct backend *,
 void VBT_Wait(struct worker *, struct vbc *);
 
 /* cache_vcl.c */
-void VCL_AddBackend(struct vcl *, struct backend *);
+int VCL_AddBackend(struct vcl *, struct backend *);
 void VCL_DelBackend(struct backend *);
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 141a06a..ad96330 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -65,10 +65,12 @@ struct director *
 VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 {
 	struct backend *b;
+	struct director *d;
 	struct vsb *vsb;
 	struct vcl *vcl;
 	struct tcp_pool *tp = NULL;
 	const struct vrt_backend_probe *vbp;
+	int retval;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
@@ -123,9 +125,15 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	if (vbp != NULL)
 		VBP_Insert(b, vbp, tp);
 
-	VCL_AddBackend(ctx->vcl, b);
+	retval = VCL_AddBackend(ctx->vcl, b);
+
+	if (retval == 0)
+		return (b->director);
 
-	return (b->director);
+	d = b->director;
+	VRT_delete_backend(ctx, &d);
+	AZ(d);
+	return (NULL);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 8f41773..a6d0c26 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -193,12 +193,16 @@ VCL_Rel(struct vcl **vcc)
 
 /*--------------------------------------------------------------------*/
 
-void
+int
 VCL_AddBackend(struct vcl *vcl, struct backend *be)
 {
 
 	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
 	CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
+
+	if (vcl->temp == vcl_temp_cooling)
+		return (1);
+
 	Lck_Lock(&vcl_mtx);
 	VTAILQ_INSERT_TAIL(&vcl->backend_list, be, vcl_list);
 	Lck_Unlock(&vcl_mtx);
@@ -208,6 +212,8 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
 		VBE_Event(be, VCL_EVENT_WARM);
 	} else if (vcl->temp != vcl_temp_init)
 		WRONG("Dynamic Backends can only be added to warm VCLs");
+
+	return (0);
 }
 
 void
diff --git a/doc/sphinx/reference/directors.rst b/doc/sphinx/reference/directors.rst
index 8ad919b..10e41d6 100644
--- a/doc/sphinx/reference/directors.rst
+++ b/doc/sphinx/reference/directors.rst
@@ -110,7 +110,9 @@ Finally, Varnish will take care of event propagation for *all* native backends,
 but dynamic backends can only be created when the VCL is warm. If your backends
 are created by an independent thread (basically outside of VCL scope) you must
 subscribe to VCL events and watch for VCL state (see
-:ref:`ref-vmod-event-functions`). You are also encouraged to comply with the
+:ref:`ref-vmod-event-functions`). Varnish will panic if you try to create a
+backend on a cold VCL, and ``VRT_new_backend`` will return ``NULL`` if the VCL
+is cooling. You are also encouraged to comply with the
 :ref:`ref_vcl_temperature` in general.
 
 



More information about the varnish-commit mailing list