[master] cfcfc6a Fix sporadic timeouts if we got cancelled

Federico G. Schwindt fgsch at lodoss.net
Sat Jan 28 19:03:04 CET 2017


commit cfcfc6a21575cc9dcd0c16a3785e60df5802c231
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Sat Jan 28 17:32:57 2017 +0000

    Fix sporadic timeouts if we got cancelled
    
    If we receive a cancellation during pthread_cond_(timed)wait() we will
    own the mutex on the way out. Avoid locking it twice, otherwise we
    will deadlock.

diff --git a/bin/varnishtest/vtc_barrier.c b/bin/varnishtest/vtc_barrier.c
index 8eb0348..ddbf828 100644
--- a/bin/varnishtest/vtc_barrier.c
+++ b/bin/varnishtest/vtc_barrier.c
@@ -408,6 +408,7 @@ void
 cmd_barrier(CMD_ARGS)
 {
 	struct barrier *b, *b2;
+	int r;
 
 	(void)priv;
 	(void)cmd;
@@ -416,7 +417,8 @@ cmd_barrier(CMD_ARGS)
 		AZ(pthread_mutex_lock(&barrier_mtx));
 		/* Reset and free */
 		VTAILQ_FOREACH_SAFE(b, &barriers, list, b2) {
-			AZ(pthread_mutex_lock(&b->mtx));
+			r = pthread_mutex_trylock(&b->mtx);
+			assert(r == 0 || r == EBUSY);
 			switch (b->type) {
 			case BARRIER_COND:
 				break;



More information about the varnish-commit mailing list