facebook-ios-sdk icon indicating copy to clipboard operation
facebook-ios-sdk copied to clipboard

Data race in FBSDKLogger

Open jacobsapps opened this issue 1 year ago • 2 comments

Checklist before submitting a bug report

Xcode version

14.3

Facebook iOS SDK version

16.0.0

Dependency Manager

SPM

SDK Framework

Core

Goals

I don't want my app to crash because of the Facebook SDK.

Expected results

I don't want my app to crash because of the Facebook SDK.

Actual results

Data races are being warned against by Thread Sanitizer.

This makes me a little anxious; since it introduces a potential crash source under which I have no control. Would you be able to investigate this please?

Steps to reproduce

  1. Integrate FB sdk
  2. Turn on TSan
  3. Run app

Code samples & details

`/facebook-ios-sdk/FBSDKCoreKit/FBSDKCoreKit/FBSDKLogger.m:195 Race on a library object in +[FBSDKLogger registerStringToReplace:replaceWith:] at 0x11a519380`

`Location is a 32-byte heap object at 0x11a519380`

After calling `FacebookCore.ApplicationDelegate.shared.application(UIApplication.shared, didFinishLaunchingWithOptions: launchOptions)` after launch:


Mutex M0 created
#0	0x000000010a3812f0 in wrap_objc_sync_enter ()
#1	0x0000000105b2396c in -[FBSDKAppEventsConfigurationManager loadAppEventsConfigurationWithBlock:] at /facebook-ios-sdk/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKAppEventsConfigurationManager.m:80

After calling FacebookCore.ApplicationDelegate.shared.application(UIApplication.shared, didFinishLaunchingWithOptions: launchOptions) after SceneDelegate sceneDidBecomeActive:

Mutating access by thread 1
#0	0x000000018045344c in -[__NSDictionaryM setObject:forKey:] ()
#1	0x0000000105b48720 in +[FBSDKLogger registerStringToReplace:replaceWith:] at /facebook-ios-sdk/FBSDKCoreKit/FBSDKCoreKit/FBSDKLogger.m:195

jacobsapps avatar May 05 '23 08:05 jacobsapps

After I updated Facebook SDK to 16.0.1 (from 14.1.0), the crashlytics begins to register some new crashes in the [FBSDKLogger registerStringToReplace:replaceWith:] method:

Crashed: com.apple.main-thread
0  CoreFoundation                 0x2a15c cow_cleanup + 120
1  CoreFoundation                 0x62458 -[__NSDictionaryM dealloc] + 148
2  Foundry                        0x409188 +[FBSDKLogger registerStringToReplace:replaceWith:] + 195 (FBSDKLogger.m:195)
3  Foundry                        0x4026e0 -[FBSDKGraphRequestConnection registerTokenToOmitFromLog:] + 1254 (FBSDKGraphRequestConnection.m:1254)
4  Foundry                        0x3ff6e8 -[FBSDKGraphRequestConnection urlStringForSingleRequest:forBatch:] + 691 (FBSDKGraphRequestConnection.m:691)
5  Foundry                        0x3ff104 -[FBSDKGraphRequestConnection requestWithBatch:timeout:] + 581 (FBSDKGraphRequestConnection.m:581)
6  Foundry                        0x3fdee4 -[FBSDKGraphRequestConnection start] + 360 (FBSDKGraphRequestConnection.m:360)
7  Foundry                        0x3fc5bc -[FBSDKGraphRequest startWithCompletion:] + 194 (FBSDKGraphRequest.m:194)
8  Foundry                        0x3e23c4 __45-[FBSDKAppEvents flushOnMainQueue:forReason:]_block_invoke + 1265 (FBSDKAppEvents.m:1265)
9  Foundry                        0x3e09d4 __43-[FBSDKAppEvents fetchServerConfiguration:]_block_invoke_2 + 1000 (FBSDKAppEvents.m:1000)
10 Foundry                        0x41b54c -[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:] + 188 (FBSDKServerConfigurationManager.m:188)
11 Foundry                        0x3e05ac __43-[FBSDKAppEvents fetchServerConfiguration:]_block_invoke + 927 (FBSDKAppEvents.m:927)
12 Foundry                        0x3e4584 -[FBSDKAppEventsConfigurationManager _processResponse:error:] + 124 (FBSDKAppEventsConfigurationManager.m:124)
13 Foundry                        0x403744 -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] + 32 (FBSDKGraphRequestMetadata.m:32)
14 Foundry                        0x400e40 __82-[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:]_block_invoke + 967 (FBSDKGraphRequestConnection.m:967)
15 Foundry                        0x400d60 -[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:] + 1000 (FBSDKGraphRequestConnection.m:1000)
16 Foundry                        0x400a04 __65-[FBSDKGraphRequestConnection _completeWithResults:networkError:]_block_invoke + 949 (FBSDKGraphRequestConnection.m:949)
17 CoreFoundation                 0xa1cc __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
18 CoreFoundation                 0x25824 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 196
19 Foundry                        0x4007b4 -[FBSDKGraphRequestConnection _completeWithResults:networkError:] + 926 (FBSDKGraphRequestConnection.m:926)
20 Foundry                        0x3ffcf0 -[FBSDKGraphRequestConnection completeFBSDKURLSessionWithResponse:data:networkError:] + 783 (FBSDKGraphRequestConnection.m:783)
21 libdispatch.dylib              0x2320 _dispatch_call_block_and_release + 32
22 libdispatch.dylib              0x3eac _dispatch_client_callout + 20
23 libdispatch.dylib              0x126a4 _dispatch_main_queue_drain + 928
24 libdispatch.dylib              0x122f4 _dispatch_main_queue_callback_4CF + 44
25 CoreFoundation                 0x98c28 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
26 CoreFoundation                 0x7a560 __CFRunLoopRun + 1992
27 CoreFoundation                 0x7f3ec CFRunLoopRunSpecific + 612
28 GraphicsServices               0x135c GSEventRunModal + 164
29 UIKitCore                      0x39d6e8 -[UIApplication _run] + 888
30 UIKitCore                      0x39d34c UIApplicationMain + 340
31 enjoei                         0x3079c main + 13 (main.swift:13)
32 ???                            0x1bdf96dec (Missing)

aleufms avatar Jun 12 '23 15:06 aleufms

https://github.com/facebook/facebook-ios-sdk/issues/2182 would be same issue.

aleufms avatar Jun 12 '23 15:06 aleufms