[master] 5a28588 Delay the accept task until all initialization has been completed.

Martin Blix Grydeland martin at varnish-cache.org
Mon Nov 19 14:59:30 CET 2012


commit 5a28588f03b542240d1a80624f2737e2ed815639
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Nov 19 11:06:36 2012 +0100

    Delay the accept task until all initialization has been completed.
    
    This resolves the race where the pools might accept connections and
    start processing them before a lot of the initialization routines has
    finished.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 6d4fe86..1383ffb 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -940,6 +940,7 @@ void PipeRequest(struct req *req);
 
 /* cache_pool.c */
 void Pool_Init(void);
+void Pool_Accept(void);
 void Pool_Work_Thread(void *priv, struct worker *w);
 int Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how);
 
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index ac36308..468401b 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -228,6 +228,8 @@ child_main(void)
 	if (FEATURE(FEATURE_WAIT_SILO))
 		SMP_Ready();
 
+	Pool_Accept();
+
 	CLI_Run();
 
 	STV_close();
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index 0e0d9dd..4e7bd7c 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -76,6 +76,7 @@ struct pool {
 
 static struct lock		pool_mtx;
 static pthread_t		thr_pool_herder;
+static unsigned			pool_accepting = 0;
 
 /*--------------------------------------------------------------------
  */
@@ -128,6 +129,12 @@ pool_accept(struct worker *wrk, void *arg)
 	CHECK_OBJ_NOTNULL(ps->lsock, LISTEN_SOCK_MAGIC);
 	assert(sizeof *wa == WS_Reserve(wrk->aws, sizeof *wa));
 	wa = (void*)wrk->aws->f;
+
+	/* Delay until we are ready (flag is set when all
+	 * initialization has finished) */
+	while (!pool_accepting)
+		VTIM_sleep(.1);
+
 	while (1) {
 		memset(wa, 0, sizeof *wa);
 		wa->magic = WRK_ACCEPT_MAGIC;
@@ -484,6 +491,14 @@ pool_poolherder(void *priv)
 /*--------------------------------------------------------------------*/
 
 void
+Pool_Accept(void)
+{
+
+	ASSERT_CLI();
+	pool_accepting = 1;
+}
+
+void
 Pool_Init(void)
 {
 



More information about the varnish-commit mailing list