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.
This commit is contained in:
Wang Yuan 2020-08-24 18:54:33 +08:00 committed by GitHub
parent 5449a2a8b5
commit 6b4ae919e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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