Skip to content

Commit 3c7348c

Browse files
namsicjhpark816
authored andcommitted
FIX: Add shutdown_lock for memcached_shutdown
1 parent 659aa16 commit 3c7348c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

memcached.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void UNLOCK_SETTING(void) {
8585
pthread_mutex_unlock(&setting_lock);
8686
}
8787

88+
static pthread_mutex_t shutdown_lock = PTHREAD_MUTEX_INITIALIZER;
8889
volatile sig_atomic_t memcached_shutdown=0;
8990

9091
/*
@@ -14541,7 +14542,11 @@ static void remove_pidfile(const char *pid_file)
1454114542

1454214543
static void shutdown_server(void)
1454314544
{
14544-
memcached_shutdown = 1;
14545+
pthread_mutex_lock(&shutdown_lock);
14546+
if (memcached_shutdown == 0) {
14547+
memcached_shutdown = 1;
14548+
}
14549+
pthread_mutex_unlock(&shutdown_lock);
1454514550
}
1454614551

1454714552
static void sigterm_handler(int sig)
@@ -15824,7 +15829,9 @@ int main (int argc, char **argv)
1582415829
mc_logger->log(EXTENSION_LOG_INFO, NULL, "Listen sockets closed.\n");
1582515830

1582615831
/* 4) shutdown all threads */
15832+
pthread_mutex_lock(&shutdown_lock);
1582715833
memcached_shutdown = 2;
15834+
pthread_mutex_unlock(&shutdown_lock);
1582815835
threads_shutdown();
1582915836
release_independent_stats(default_thread_stats);
1583015837
if (default_topkeys) {

0 commit comments

Comments
 (0)