[master] cec1281 Don't close and reopen(+bind) the acceptor socket in the server instances whenever we give the server instance more work, doing so runs into a dark and murky corner somewhere in Stevens and Solaris sometimes doesn't like that.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 6 10:31:31 CEST 2014


commit cec12811e38df53ea1e9a3307788b7741496c80a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 6 08:27:44 2014 +0000

    Don't close and reopen(+bind) the acceptor socket in the server
    instances whenever we give the server instance more work, doing
    so runs into a dark and murky corner somewhere in Stevens and
    Solaris sometimes doesn't like that.
    
    The trouble is that the initial bind(2) asks the kernel to assign
    a port, but the subsequent insist on reusing that port, and that,
    in some cases, could mean toruble which cannot be allowed.
    
    Add a "-break" instruction to server so that test case c00035 can
    still work.
    
    Spotted by:	Nils Goroll / UPLEX

diff --git a/bin/varnishtest/tests/c00035.vtc b/bin/varnishtest/tests/c00035.vtc
index 83400f1..9463548 100644
--- a/bin/varnishtest/tests/c00035.vtc
+++ b/bin/varnishtest/tests/c00035.vtc
@@ -1,6 +1,6 @@
 varnishtest "Dropping polling of a backend"
 
-server s1 -repeat 1 {
+server s1 -repeat 20 {
 	rxreq
 	txresp
 } -start
@@ -32,7 +32,7 @@ delay 1
 varnish v1 -cliok "vcl.list"
 varnish v1 -cliok "debug.health"
 
-server s1 {
+server s1 -break {
 	rxreq
 	expect req.url == /foo
 	txresp -bodylen 4
diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c
index 86cf293..396a869 100644
--- a/bin/varnishtest/vtc_server.c
+++ b/bin/varnishtest/vtc_server.c
@@ -187,6 +187,23 @@ server_start(struct server *s)
 }
 
 /**********************************************************************
+ * Force stop the server thread
+ */
+
+static void
+server_break(struct server *s)
+{
+	void *res;
+
+	CHECK_OBJ_NOTNULL(s, SERVER_MAGIC);
+	vtc_log(s->vl, 2, "Breaking for server");
+	(void)pthread_cancel(s->tp);
+	AZ(pthread_join(s->tp, &res));
+	s->tp = 0;
+	s->run = 0;
+}
+
+/**********************************************************************
  * Wait for server thread to stop
  */
 
@@ -202,8 +219,6 @@ server_wait(struct server *s)
 		vtc_log(s->vl, 0, "Server returned \"%p\"",
 		    (char *)res);
 	s->tp = 0;
-	VTCP_close(&s->sock);
-	s->sock = -1;
 	s->run = 0;
 }
 
@@ -246,6 +261,10 @@ cmd_server(CMD_ARGS)
 				(void)pthread_cancel(s->tp);
 				server_wait(s);
 			}
+			if (s->sock >= 0) {
+				VTCP_close(&s->sock);
+				s->sock = -1;
+			}
 			server_delete(s);
 		}
 		return;
@@ -271,6 +290,12 @@ cmd_server(CMD_ARGS)
 			server_wait(s);
 			continue;
 		}
+
+		if (!strcmp(*av, "-break")) {
+			server_break(s);
+			continue;
+		}
+
 		/*
 		 * We do an implict -wait if people muck about with a
 		 * running server.
@@ -285,6 +310,10 @@ cmd_server(CMD_ARGS)
 			continue;
 		}
 		if (!strcmp(*av, "-listen")) {
+			if (s->sock >= 0) {
+				VTCP_close(&s->sock);
+				s->sock = -1;
+			}
 			bprintf(s->listen, "%s", av[1]);
 			AZ(VSS_parse(s->listen, &s->addr, &s->port));
 			av++;



More information about the varnish-commit mailing list