From 879f3b1fd5cf6b459f5ccd178aeb706ecfd407d0 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Fri, 3 May 2024 14:50:23 +0200 Subject: [PATCH] impr: Remove not needed log for logging (#3934) Every log message needs to acquire a lock to evaluate whether the logger should log it. #3303 added this logic to fix a data race the thread sanitizer job found. As the SDK only calls the configure method when starting, we don't need to put a synchronized keyword around the code that evaluates the log level. This PR replaces the synchronized keyword by ignoring the thread sanitizer. --- CHANGELOG.md | 4 ++++ Sources/Sentry/SentryLog.m | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d663ae37ab..090f1fa4138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Ignore SentryFramesTracker thread sanitizer data races (#3922) - Handle no releaseName in WatchDogTerminationLogic (#3919) +### Improvements + +- Remove not needed lock for logging (#3934) + ## 8.25.0 ### Features diff --git a/Sources/Sentry/SentryLog.m b/Sources/Sentry/SentryLog.m index 4335fc67fd0..d53d219a57b 100644 --- a/Sources/Sentry/SentryLog.m +++ b/Sources/Sentry/SentryLog.m @@ -1,4 +1,5 @@ #import "SentryLog.h" +#import "SentryInternalCDefines.h" #import "SentryLevelMapper.h" #import "SentryLogOutput.h" @@ -37,10 +38,12 @@ + (void)logWithMessage:(NSString *)message andLevel:(SentryLevel)level } + (BOOL)willLogAtLevel:(SentryLevel)level + SENTRY_DISABLE_THREAD_SANITIZER( + "The SDK usually configures the log level and isDebug once when it starts. For tests, we " + "accept a data race causing some log messages of the wrong level over using a synchronized " + "block for this method, as it's called frequently in production.") { - @synchronized(logConfigureLock) { - return isDebug && level != kSentryLevelNone && level >= diagnosticLevel; - } + return isDebug && level != kSentryLevelNone && level >= diagnosticLevel; } // Internal and only needed for testing.