From 3361bab0388f7cdad50e1c67e1127801fda05685 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Sat, 7 Mar 2015 06:10:41 +0100 Subject: glfsheal: Avoid infinite loop on exit Make sure we do not get stuck looping forever in event_dispatch_destroy() by limiting the retries when waiting for other threads, and by giving up when writing to other thread fails. This fixes regression tests hanging forever on NetBSD. BUG: 1129939 Change-Id: I4459cfb1ab7294e8c15a21b592e0154c22abae07 Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/9825 Tested-by: Gluster Build System Reviewed-by: Niels de Vos Reviewed-by: Shyamsundar Ranganathan Reviewed-by: Jeff Darcy Reviewed-by: Vijay Bellur --- libglusterfs/src/event.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index f19d43a0ab1..b956d25595f 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -235,10 +235,14 @@ event_dispatch_destroy (struct event_pool *event_pool) pthread_mutex_lock (&event_pool->mutex); { /* Write to pipe(fd[1]) and then wait for 1 second or until - * a poller thread that is dying, broadcasts. + * a poller thread that is dying, broadcasts. Make sure we + * do not loop forever by limiting to 10 retries */ - while (event_pool->activethreadcount > 0) { - write (fd[1], "dummy", 6); + int retry = 0; + + while (event_pool->activethreadcount > 0 && retry++ < 10) { + if (write (fd[1], "dummy", 6) == -1) + break; sleep_till.tv_sec = time (NULL) + 1; ret = pthread_cond_timedwait (&event_pool->cond, &event_pool->mutex, -- cgit