From 6b4ae919e8f3ebe883902e10305d29a083b3c679 Mon Sep 17 00:00:00 2001 From: Wang Yuan Date: Mon, 24 Aug 2020 18:54:33 +0800 Subject: [PATCH] Fix data race in bugReportStart (#7700) The previous fix using _Atomic was insufficient, since we check and set it in different places. The implications of this bug are just that a portion of the bug report will be shown twice, in the race case of two concurrent crashes. --- src/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/debug.c b/src/debug.c index 5cfda59c9..b05dc344e 100644 --- a/src/debug.c +++ b/src/debug.c @@ -55,7 +55,8 @@ typedef ucontext_t sigcontext_t; #endif /* Globals */ -static _Atomic int bug_report_start = 0; /* True if bug report header was already logged. */ +static int bug_report_start = 0; /* True if bug report header was already logged. */ +static pthread_mutex_t bug_report_start_mutex = PTHREAD_MUTEX_INITIALIZER; /* Forward declarations */ void bugReportStart(void); @@ -919,11 +920,13 @@ void _serverPanic(const char *file, int line, const char *msg, ...) { } void bugReportStart(void) { + pthread_mutex_lock(&bug_report_start_mutex); if (bug_report_start == 0) { serverLogRaw(LL_WARNING|LL_RAW, "\n\n=== REDIS BUG REPORT START: Cut & paste starting from here ===\n"); bug_report_start = 1; } + pthread_mutex_unlock(&bug_report_start_mutex); } #ifdef HAVE_BACKTRACE