Skip to content

Commit 7ff11f4

Browse files
JesusRojassleojaygoogle
authored andcommitted
[Crashlytics] Fix deadlock in user logging on reentrant queue access. (#16163) (#16192)
1 parent 9768df6 commit 7ff11f4

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Crashlytics/Crashlytics/Components/FIRCLSContext.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ void FIRCLSContextBaseInit(void) {
245245
NSString* exceptionQueueName = [sdkBundleID stringByAppendingString:@".exception"];
246246

247247
_firclsLoggingQueue = dispatch_queue_create([loggingQueueName UTF8String], DISPATCH_QUEUE_SERIAL);
248+
if (_firclsLoggingQueue) {
249+
dispatch_queue_set_specific(_firclsLoggingQueue, &_firclsLoggingQueue, &_firclsLoggingQueue,
250+
NULL);
251+
}
248252
_firclsBinaryImageQueue =
249253
dispatch_queue_create([binaryImagesQueueName UTF8String], DISPATCH_QUEUE_SERIAL);
250254
_firclsExceptionQueue =
@@ -437,3 +441,19 @@ bool FIRCLSContextRecordMetadata(NSString* rootPath, const FIRCLSContextInitData
437441

438442
return true;
439443
}
444+
445+
void FIRCLSExecuteOnLoggingQueue(void (^block)(void)) {
446+
if (!block) {
447+
return;
448+
}
449+
450+
if (!_firclsLoggingQueue) {
451+
FIRCLSSDKLogWarn(
452+
"FIRCLSExecuteOnLoggingQueue invoked with NULL logging queue; running block inline.\n");
453+
block();
454+
} else if (dispatch_get_specific(&_firclsLoggingQueue) != NULL) {
455+
block();
456+
} else {
457+
dispatch_sync(_firclsLoggingQueue, block);
458+
}
459+
}

Crashlytics/Crashlytics/Components/FIRCLSGlobals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ extern dispatch_queue_t _firclsExceptionQueue;
2525
#define FIRCLSGetBinaryImageQueue() (_firclsBinaryImageQueue)
2626
#define FIRCLSGetExceptionQueue() (_firclsExceptionQueue)
2727

28+
void FIRCLSExecuteOnLoggingQueue(void (^block)(void));
29+
2830
__END_DECLS

Crashlytics/Crashlytics/Components/FIRCLSUserLogging.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void FIRCLSUserLoggingRecordKeysAndValues(NSDictionary *keysAndValues,
283283
}
284284
}
285285

286-
dispatch_sync(FIRCLSGetLoggingQueue(), ^{
286+
FIRCLSExecuteOnLoggingQueue(^{
287287
FIRCLSUserLoggingWriteKeysAndValues(sanitizedKeysAndValues, storage, counter,
288288
containsNullValue);
289289
});
@@ -541,7 +541,7 @@ void FIRCLSUserLoggingWriteAndCheckABFiles(FIRCLSUserLoggingABStorage *storage,
541541
}
542542
}
543543

544-
dispatch_sync(FIRCLSGetLoggingQueue(), ^{
544+
FIRCLSExecuteOnLoggingQueue(^{
545545
FIRCLSFile file;
546546

547547
if (!FIRCLSFileInitWithPath(&file, *activePath, true)) {

0 commit comments

Comments
 (0)