diff options
author | Wang Yuan <wangyuan21@baidu.com> | 2020-08-24 18:54:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-24 13:54:33 +0300 |
commit | 6b4ae919e8f3ebe883902e10305d29a083b3c679 (patch) | |
tree | 7154c3847957d9c244bddb7ad9320c3730ad0292 | |
parent | 5449a2a8b54db6a57b564e453c9f7075ebb81f79 (diff) | |
download | redis-6b4ae919e8f3ebe883902e10305d29a083b3c679.tar.gz |
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.
-rw-r--r-- | src/debug.c | 5 |
1 files changed, 4 insertions, 1 deletions
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 |