microsoft / appcenter-sdk-apple

Development repository for the App Center SDK for iOS, macOS and tvOS.
Other
558 stars 222 forks source link

Crash due to attempting to store too much in NSUserDefaults #2483

Closed hakonk closed 3 months ago

hakonk commented 1 year ago

Description

When using the SDK for tvOS applications, I have experienced crashes in production where the following error symbol occurs: __CFPREFERENCES_HAS_DETECTED_THIS_APP_TRYING_TO_STORE_TOO_MUCH_DATA__. tvOS apps have considerably less available storage as opposed to iOS apps. While it may no longer be capped to 500KB, it is still small enough to cause crashes when attempting to write above the byte count limit. When the AppCenter SDK piggy backs on the existing standard instance of NSUserDefaults, there may already be a lot of data stored, which means the SDK depends on the consuming app's handling of the storage.

Perhaps it would be better to have a separate NSUserDefaults suite for the AppCenter SDK, while also implementing some handling of the storage in the event of approaching the limit.

This is the simplified stack trace:

__pthread_kill
pthread_kill
abort
__CFPREFERENCES_HAS_DETECTED_THIS_APP_TRYING_TO_STORE_TOO_MUCH_DATA__
-[CFPrefsPlistSource handlePossibleOversizedMessage:forWritingKeys:values:count:]
-[CFPrefsPlistSource handleErrorReply:toMessage:settingKeys:toValues:count:retryCount:retryContinuation:]
__99-[CFPrefsPlistSource sendFullyPreparedMessage:toConnection:settingValues:forKeys:count:retryCount:]_block_invoke
-[_CFXPreferences withConnectionForRole:andUserIdentifier:performBlock:]
-[CFPrefsPlistSource sendFullyPreparedMessage:toConnection:settingValues:forKeys:count:retryCount:]
-[CFPrefsPlistSource sendMessageSettingValues:forKeys:count:]
-[CFPrefsPlistSource alreadylocked_setPrecopiedValues:forKeys:count:from:]
-[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:]
-[CFPrefsSource setValues:forKeys:count:copyValues:from:]
-[CFPrefsSearchListSource alreadylocked_setPrecopiedValues:forKeys:count:from:]
-[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:]
-[CFPrefsSource setValue:forKey:from:]
__76-[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:]_block_invoke
__108-[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke
-[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:]
-[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:]
_CFPreferencesSetAppValueWithContainerAndConfiguration
-[NSUserDefaults(NSUserDefaults) setObject:forKey:]
-[MSACAppCenterUserDefaults setObject:forKey:] (MSACAppCenterUserDefaults.m:83)
-[MSACSessionContext setSessionId:] (MSACSessionContext.m:64)

Repro Steps

Not sure how to reproduce, but the stack trace shows an exception is thrown as a result of

-[MSACAppCenterUserDefaults setObject:forKey:]

, which in turn calls on NSUserDefaults.

Details

  1. Which SDK version are you using?
    • 5.0.2
  2. Which OS version did you experience the issue on?
    • tvOS 16
  3. Which Xcode version did you build the app with?
    • 14.3
  4. What device version did you see this error on? Were you using an emulator or a physical device?
    • e.g. Apple TV 4th generation physical device
  5. What language are you using?
    • [ ] Objective C
    • [X] Swift
DmitriyKirakosyan commented 1 year ago

Hi @hakonk , thank you so much for this request and I apologize for the delayed response.

If I understand correctly, the issue you've raised primarily impacts tvOS due to its limited storage size. Is my understanding accurate? I will categorize this as a feature request, but I cannot provide an ETA at this moment. Currently, our team is prioritizing reliability and addressing higher-priority issues.

hakonk commented 1 year ago

Hi! Thanks for answering.

Yep, this is primarily an issue on tvOS. Fully understandable that other issues have a higher priority.

zenangst commented 7 months ago

@DmitriyKirakosyan any updates on this?

DmitriyKirakosyan commented 3 months ago

As we do not have plans to fix this bug in the next year, I'm closing the issue.