[master] f00f23d8f varnishtest: Don't cancel tunnel threads

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri May 28 14:21:05 UTC 2021


commit f00f23d8f892a4b05e84d152e109e3da86a4d786
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri May 28 16:16:29 2021 +0200

    varnishtest: Don't cancel tunnel threads
    
    Unlike other threads we cancel in varnishtest there's 2 per tunnel and
    they need coordination between each other. The spec thread remains as-is
    and the poll thread now checks vtc_stop after each condwait.
    
    With this I'm no longer able to reproduce a21's timeout.
    
    Reverts d4cf677ae48a46317bab432104c3729913d7a9db

diff --git a/bin/varnishtest/tests/a00021.vtc b/bin/varnishtest/tests/a00021.vtc
index 43688b0f8..9eb158582 100644
--- a/bin/varnishtest/tests/a00021.vtc
+++ b/bin/varnishtest/tests/a00021.vtc
@@ -44,5 +44,3 @@ client c2 -connect "${t2_sock}" {
 	txreq
 	rxresp
 } -run
-
-tunnel t2 -wait
diff --git a/bin/varnishtest/vtc_tunnel.c b/bin/varnishtest/vtc_tunnel.c
index 8e1f9e595..d26c73e16 100644
--- a/bin/varnishtest/vtc_tunnel.c
+++ b/bin/varnishtest/vtc_tunnel.c
@@ -386,11 +386,14 @@ tunnel_poll_thread(void *priv)
 	while (tunnel_is_open(t) && !vtc_stop) {
 		AZ(pthread_mutex_lock(&t->mtx));
 		/* NB: can be woken up by `tunnel tX -wait` */
-		while (t->state == TUNNEL_ACCEPT)
+		while (t->state == TUNNEL_ACCEPT && !vtc_stop)
 			AZ(pthread_cond_wait(&t->cond, &t->mtx));
 		state = t->state;
 		AZ(pthread_mutex_unlock(&t->mtx));
 
+		if (vtc_stop)
+			break;
+
 		assert(state < TUNNEL_POLL_DONE);
 
 		memset(pfd, 0, sizeof pfd);
@@ -415,6 +418,9 @@ tunnel_poll_thread(void *priv)
 		}
 		AZ(pthread_mutex_unlock(&t->mtx));
 
+		if (vtc_stop)
+			break;
+
 		tunnel_write(t, vl, t->send_lane, "Sending");
 		tunnel_write(t, vl, t->recv_lane, "Receiving");
 	}
@@ -651,14 +657,10 @@ tunnel_wait(struct tunnel *t)
 	AZ(pthread_cond_signal(&t->cond));
 
 	AZ(pthread_join(t->tspec, &res));
-	if (res == PTHREAD_CANCELED && !vtc_stop)
-		vtc_fatal(t->vl, "Tunnel spec canceled");
 	if (res != NULL && !vtc_stop)
 		vtc_fatal(t->vl, "Tunnel spec returned \"%p\"", res);
 
 	AZ(pthread_join(t->tpoll, &res));
-	if (res == PTHREAD_CANCELED && !vtc_stop)
-		vtc_fatal(t->vl, "Tunnel poll canceled");
 	if (res != NULL && !vtc_stop)
 		vtc_fatal(t->vl, "Tunnel poll returned \"%p\"", res);
 
@@ -679,7 +681,6 @@ static void
 tunnel_reset(void)
 {
 	struct tunnel *t;
-	enum tunnel_state_e state;
 
 	while (1) {
 		AZ(pthread_mutex_lock(&tunnel_mtx));
@@ -691,15 +692,7 @@ tunnel_reset(void)
 		if (t == NULL)
 			break;
 
-		AZ(pthread_mutex_lock(&t->mtx));
-		state = t->state;
-		if (state < TUNNEL_POLL_DONE)
-			(void)pthread_cancel(t->tpoll);
-		if (state < TUNNEL_SPEC_DONE)
-			(void)pthread_cancel(t->tspec);
-		AZ(pthread_mutex_unlock(&t->mtx));
-
-		if (state != TUNNEL_STOPPED)
+		if (t->state != TUNNEL_STOPPED)
 			tunnel_wait(t);
 		tunnel_delete(t);
 	}


More information about the varnish-commit mailing list