summaryrefslogtreecommitdiff
path: root/logger.c
diff options
context:
space:
mode:
authorSailesh Mukil <sailesh@apache.org>2022-08-10 18:29:31 -0700
committerdormando <dormando@rydia.net>2022-08-10 21:53:11 -0700
commit0e0b0c2d373c738b402f6725b36b5b22e935ca0c (patch)
tree5fae1a94c6990586f02397c4c4643f366ade6556 /logger.c
parentefacd3090e8d3407c60a2e3df53fa9cc7534c45f (diff)
downloadmemcached-0e0b0c2d373c738b402f6725b36b5b22e935ca0c.tar.gz
Race leads to deadlock during shutdown (sigterm/sigusr1)
We've noticed in some rare cases, that sending a sigterm to a memcached process could lead to a race condition which leads to a deadlock of the process. The worker threads are stuck on 'worker_hang_lock' because the shutdown process hasn't completed yet. The shudown process hasn't completed since the logger thread signals 'logger_stack_cond' without locking its corresponding 'logger_stack_lock'. This could cause the signal to get lost, causing the logger thread to wait indefinitely on 'logger_stack_cond' in logger_thread().
Diffstat (limited to 'logger.c')
-rw-r--r--logger.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/logger.c b/logger.c
index 0ef822c..89dfa0b 100644
--- a/logger.c
+++ b/logger.c
@@ -826,8 +826,12 @@ static int start_logger_thread(void) {
}
static int stop_logger_thread(void) {
+ // Guarantees that the logger thread is waiting on 'logger_stack_cond'
+ // before we signal it.
+ pthread_mutex_lock(&logger_stack_lock);
do_run_logger_thread = 0;
pthread_cond_signal(&logger_stack_cond);
+ pthread_mutex_unlock(&logger_stack_lock);
pthread_join(logger_tid, NULL);
return 0;
}