AppsFlyerSDK / AppsFlyerFramework

AppsFlyer Apple SDK
https://support.appsflyer.com/hc/en-us/articles/207032066-AppsFlyer-SDK-Integration-iOS
Other
170 stars 92 forks source link

-[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] Issue #147

Closed pmanuelli closed 3 years ago

pmanuelli commented 3 years ago

Report

SDK Version

6.1.2

What did you do?

Integrated latest SDK version (6.1.2) and run app in the production environment.

What did you expect to happen?

The app does not crash.

What happened instead?

The app crashes on [AFSDKUserDefaultsStorage setDouble:forKey:]

Stack trace:

Crashed: com.appsflyer.serial
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000006365fb840
-[AFSDKUserDefaultsStorage setDouble:forKey:]

Crashed: com.appsflyer.serial
0  libobjc.A.dylib                0x198985020 objc_release + 16
1  Foundation                     0x1857378f0 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 668
2  Foundation                     0x1856713f8 -[NSObject(NSKeyValueObservingPrivate) _notifyObserversOfChangeFromValuesForKeys:toValuesForKeys:] + 836
3  CoreFoundation                 0x1842fc60c -[CFPrefsSource forEachObserver:] + 336
4  CoreFoundation                 0x1842fde3c -[CFPrefsSource _notifyObserversOfChangeFromValuesForKeys:toValuesForKeys:] + 112
5  CoreFoundation                 0x184471b68 ___CFPrefsDeliverPendingKVONotificationsGuts_block_invoke + 428
6  CoreFoundation                 0x1843553f0 __CFDictionaryApplyFunction_block_invoke + 28
7  CoreFoundation                 0x18443bd94 CFBasicHashApply + 144
8  CoreFoundation                 0x1843553ac CFDictionaryApplyFunction + 240
9  CoreFoundation                 0x18446d748 _CFPrefsDeliverPendingKVONotificationsGuts + 300
10 CoreFoundation                 0x18446bf44 -[_CFXPreferences _deliverPendingKVONotifications] + 96
11 CoreFoundation                 0x18442f194 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 432
12 CoreFoundation                 0x18442e720 normalizeQuintuplet + 356
13 CoreFoundation                 0x18442efbc -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 152
14 CoreFoundation                 0x1842f1580 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 128
15 CoreFoundation                 0x18446fdd8 _CFPreferencesSetAppValueWithContainerAndConfiguration + 136
16 Foundation                     0x18566bf6c -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 68
17 XXXXXXXXX                      0x102cb6e94 -[AFSDKUserDefaultsStorage setDouble:forKey:] + 4345245332
18 XXXXXXXXX                      0x102ccef48 -[AppsFlyerLib getTimePassedSinceLastLaunch] + 4345343816
19 XXXXXXXXX                      0x102ccbd64 -[AppsFlyerLib getEventParameters:] + 4345331044
20 XXXXXXXXX                      0x102ccf598 -[AppsFlyerLib callServerWithEventName:eventValues:options:completion:] + 4345345432
21 XXXXXXXXX                      0x102cc9c60 __45-[AppsFlyerLib __startWithCompletionHandler:]_block_invoke + 4345322592
22 libdispatch.dylib              0x18400324c _dispatch_call_block_and_release + 32
23 libdispatch.dylib              0x184004db0 _dispatch_client_callout + 20
24 libdispatch.dylib              0x18400c10c _dispatch_lane_serial_drain + 580
25 libdispatch.dylib              0x18400cc5c _dispatch_lane_invoke + 408
26 libdispatch.dylib              0x184016d78 _dispatch_workloop_worker_thread + 708
27 libsystem_pthread.dylib        0x1cd828804 _pthread_wqthread + 276
28 libsystem_pthread.dylib        0x1cd82f75c start_wqthread + 8

Please provide any other relevant information.

The issue started on version 6.1.2. All occurrences happen in iOS14.

andr-ggn commented 3 years ago

Hello,

pmanuelli commented 3 years ago

Thank you for your answer.

Yes, I'm sure. This is the content of our Podfile.lock:

  - AppsFlyerFramework (6.1.2):
    - AppsFlyerFramework/Main (= 6.1.2)
  - AppsFlyerFramework/Main (6.1.2)

Yes, we have observations like that.

I'm using Firebase to track the crashes. It does not happen so often. To the users experiencing the crash, seems to happen only once. I can't reproduce the issue locally and can't understand under which circumstances does it happen.

We were testing some changes related to the iOS14 IDFA restriction. We enabled SDAdNetwork measurements. Now we turned it off to see if the crash stops.

Yes, we are on 6.34.0.

zhangwen2016 commented 3 years ago

we have the same crash, could you help to solve this?

isimpson commented 3 years ago

We are also seeing a similar crash since update to AppsFlyer sdk v6.1.2. This is now by far our most significant crash in our app and I would like to resolve it asap. The stack trace is not quite the same but I think it could be related:

Crashed: com.appsflyer.serial
0  libsystem_kernel.dylib         0x1b2c4184c __pthread_kill + 8
1  libsystem_pthread.dylib        0x1ce19d9e8 pthread_kill + 212
2  libsystem_c.dylib              0x1907ad8f4 abort + 100
3  libsystem_malloc.dylib         0x19652d030 _malloc_put + 554
4  libsystem_malloc.dylib         0x19652d2a4 malloc_zone_error + 100
5  libsystem_malloc.dylib         0x196516a60 szone_free + 460
6  libswiftCore.dylib             0x18b7e0104 _swift_release_dealloc + 28
7  XXXXXXXXXXXXXXXXXXXXX          0x104a2a4a8 specialized AppController.updateAppsFlyerUserCustomerId(userDefaults:) + 4346078376 (<compiler-generated>:4346078376)
8  XXXXXXXXXXXXXXXXXXXXX          0x104a234d4 @objc AppController.defaultsChanged(notification:) + 4346049748 (<compiler-generated>:4346049748)
9  CoreFoundation                 0x187a64360 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
10 CoreFoundation                 0x187a64320 ___CFXRegistrationPost_block_invoke + 48
11 CoreFoundation                 0x187a63918 _CFXRegistrationPost + 400
12 CoreFoundation                 0x187a63310 _CFXNotificationPost + 696
13 Foundation                     0x188c970a0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60
14 XXXXXXXXXXXXXXXXXXXXX          0x104f05770 -[AFSDKUserDefaultsStorage setInteger:forKey:] + 4351170416
15 XXXXXXXXXXXXXXXXXXXXX          0x104f069ac -[AFSDKSKAdNetwork didReceiveConfiguration:] + 4351175084
16 XXXXXXXXXXXXXXXXXXXXX          0x104f14f20 __38-[AppsFlyerLib handleOneLinkResponse:]_block_invoke + 4351233824
17 libdispatch.dylib              0x187739298 _dispatch_call_block_and_release + 24
18 libdispatch.dylib              0x18773a280 _dispatch_client_callout + 16
19 libdispatch.dylib              0x1876e2dcc _dispatch_lane_serial_drain$VARIANT$mp + 612
20 libdispatch.dylib              0x1876e38a8 _dispatch_lane_invoke$VARIANT$mp + 424
21 libdispatch.dylib              0x1876ed338 _dispatch_workloop_worker_thread + 712
22 libsystem_pthread.dylib        0x1ce19e5a4 _pthread_wqthread + 272
23 libsystem_pthread.dylib        0x1ce1a1874 start_wqthread + 8
andr-ggn commented 3 years ago

This is a known issue.

Why? It happens because of the internal Apple bug in KVO.

When?

The following code can be a cause (used by clients):

[[NSUserDefaults standardUserDefaults] addObserver: 
          self forKeyPath: @"{SOME_KEY}" 
                  options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL];

Details:

The system starts to monitor NSUserDefaults changes and crashes in very rare cases. Before version 6.1.2, KVO was implemented inside the SDK, but due to the Apple bug, we decided to remove it. We use NSUserDefaults as storage for some values. And we try to write them down as early as possible.

The Possible Solution:

We can migrate from NSUserDefaults, which is a very laborious process. As a workaround, we strongly recommend excluding KVO for NSUserDefaults.

Similar problems occur with other SDKs like Firebase

drumih commented 3 years ago

@andr-ggn @af-fess Hi. We are still facing the same problem. Could you recommend us how to fix it? Will you fix this bug in future releases?

We don't use [[NSUserDefaults standardUserDefaults] addObserver:... in our code.

andr-ggn commented 3 years ago

@drumih Please, add symbolic breakpoint and check which framework adds this observer. Also which version of SDK do you use?

drumih commented 3 years ago

@andr-ggn we use 6.1.4. We'll check observers, thanks

pm-hai-phung commented 3 years ago

We're seeing the same crash in Firebase Crashlytics. It doesn't appear to be catastrophic at the moment, but it is our highest-rated crash.

AppsFlyer SDK: 6.1.3 Firebase Performance: 6.33.0

As far as KVO observers are concerned, we are not explicitly using KVO but through symbolic breakpoints, we can see that upon app launch the Firebase SDK is definitely adding KVO observers for NSUserDefaults via GTMLogger (see attached screenshots). UIKit and WebKit are also registering observers as well.

Screen Shot 2021-02-04 at 4 21 53 PM

Screen Shot 2021-02-04 at 4 22 01 PM

Knowing that this issue spans across the latest versions (6.1.2 - 6.1.4) and we don't have access to make changes to 3rd party SDKs, do you plan to address this issue at all?

We're happy to work with you and provide any other additional information you might need.

Crashed: com.appsflyer.serial
0  libobjc.A.dylib                0x1baef4de0 objc_release + 16
1  Foundation                     0x1a7dfe598 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 644
2  Foundation                     0x1a7d43c64 -[NSObject(NSKeyValueObservingPrivate) _notifyObserversOfChangeFromValuesForKeys:toValuesForKeys:] + 808
3  CoreFoundation                 0x1a6a64df0 -[CFPrefsSource forEachObserver:] + 312
4  CoreFoundation                 0x1a6a664f0 -[CFPrefsSource _notifyObserversOfChangeFromValuesForKeys:toValuesForKeys:] + 84
5  CoreFoundation                 0x1a6bca6bc ___CFPrefsDeliverPendingKVONotificationsGuts_block_invoke + 360
6  CoreFoundation                 0x1a6ab9ec4 __CFDictionaryApplyFunction_block_invoke + 24
7  CoreFoundation                 0x1a6b976f0 CFBasicHashApply + 136
8  CoreFoundation                 0x1a6ab9e84 CFDictionaryApplyFunction + 192
9  CoreFoundation                 0x1a6bc6754 _CFPrefsDeliverPendingKVONotificationsGuts + 288
10 CoreFoundation                 0x1a6bc515c -[_CFXPreferences _deliverPendingKVONotifications] + 92
11 CoreFoundation                 0x1a6b8b390 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 384
12 CoreFoundation                 0x1a6b8aa60 normalizeQuintuplet + 348
13 CoreFoundation                 0x1a6b8b1e8 -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 124
14 CoreFoundation                 0x1a6a5a5e8 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 100
15 CoreFoundation                 0x1a6bc8ae4 _CFPreferencesSetAppValueWithContainerAndConfiguration + 132
16 Foundation                     0x1a7d3ecc4 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 64
17 SwipeKit                       0x1056ef5cc -[AFSDKUserDefaultsStorage setDouble:forKey:] + 96
18 SwipeKit                       0x1057081c0 -[AppsFlyerLib getTimePassedSinceLastLaunch] + 212
19 SwipeKit                       0x105704ee4 -[AppsFlyerLib getEventParameters:] + 2164
20 SwipeKit                       0x105708804 -[AppsFlyerLib callServerWithEventName:eventValues:options:completion:] + 1556
21 SwipeKit                       0x105702cf4 __45-[AppsFlyerLib __startWithCompletionHandler:]_block_invoke + 900
22 libdispatch.dylib              0x1a67a6298 _dispatch_call_block_and_release + 24
23 libdispatch.dylib              0x1a67a7280 _dispatch_client_callout + 16
24 libdispatch.dylib              0x1a67834f0 _dispatch_lane_serial_drain$VARIANT$armv81 + 568
25 libdispatch.dylib              0x1a6783fdc _dispatch_lane_invoke$VARIANT$armv81 + 404
26 libdispatch.dylib              0x1a678d800 _dispatch_workloop_worker_thread + 692
27 libsystem_pthread.dylib        0x1ef2a35a4 _pthread_wqthread + 272
28 libsystem_pthread.dylib        0x1ef2a6874 start_wqthread + 8
pmanuelli commented 3 years ago

Hello! We updated our Firebase/Performance version to 7.4.0 and, along with AppsFlyer 6.1.4, the crash seems to stop.

pm-hai-phung commented 3 years ago

We'll definitely try this, @pmanuelli! Thanks for the update.

fumoboy007 commented 3 years ago

I believe this was caused by a bug in google-toolbox-for-mac. The bug has now been fixed.

andr-ggn commented 3 years ago

We will reopen the ticket, if the problem comes back