>From f79b643dd4d6858a3bca4f4b1e0e0e8953409022 Mon Sep 17 00:00:00 2001
From: Nils Goroll <nils.goroll@uplex.de>
Date: Tue, 11 Oct 2011 21:14:28 +0200
Subject: [PATCH] synchronize ccf_listen_address() on hack_ready

Partly fixes #865

This fixes a race condition between the cli thread and the acceptor
thread where the cli thread would respond to a debug.listen_address
command before the acceptor thread got around to call listen() on all
accept sockets.

This was probably only relevant for VTC tests: False negatives which
would surface for any test which connected to the Varnish server with
a low probability. Seen on Solaris.
---
 bin/varnishd/cache_acceptor.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index e6ad6e3..a3d7f73 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -376,6 +376,14 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv)
 	(void)cli;
 	(void)av;
 	(void)priv;
+
+	/*
+	 * don't tell the vtc child where to connect to before we're
+	 * ready - otherwise it may die with an ECONNREFUSED (seen on Solaris)
+	 */
+	while(!hack_ready)
+		(void)usleep(100*1000);
+
 	VTAILQ_FOREACH(ls, &heritage.socks, list) {
 		if (ls->sock < 0)
 			continue;
-- 
1.5.6.5

