Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: [OneSignalUserDefaults saveDoubleForKey:withValue:] crash #1387

Open
1 task done
jakubpetrik opened this issue Mar 19, 2024 · 8 comments
Open
1 task done

[Bug]: [OneSignalUserDefaults saveDoubleForKey:withValue:] crash #1387

jakubpetrik opened this issue Mar 19, 2024 · 8 comments

Comments

@jakubpetrik
Copy link

jakubpetrik commented Mar 19, 2024

What happened?

App crashed on start

Steps to reproduce?

Can't reproduce it myself, the crash comes from Crashlytics in AppStore build

What did you expect to happen?

App should not crash.

OneSignal iOS SDK version

5.1.3

iOS version

15

Specific iOS version

iOS 17.0.3

Relevant log output

Crashed: com.apple.main-thread
0  SwiftUI                        0x1281818 OUTLINED_FUNCTION_4 + 9336
1  SwiftUI                        0xdfb3b0 OUTLINED_FUNCTION_15 + 21652
2  SwiftUI                        0xdfaec8 OUTLINED_FUNCTION_15 + 20396
3  SwiftUI                        0x175803c OUTLINED_FUNCTION_2 + 13856
4  SwiftUI                        0x1758120 OUTLINED_FUNCTION_2 + 14084
5  SwiftUI                        0x1b7bbf8 OUTLINED_FUNCTION_18 + 17484
6  SwiftUI                        0xd6e370 objectdestroyTm + 20668
7  SwiftUI                        0xd6e67c objectdestroyTm + 21448
8  SwiftUI                        0xd6f21c objectdestroyTm + 24424
9  SwiftUI                        0x11474c0 OUTLINED_FUNCTION_11 + 40
10 SwiftUI                        0x1977230 OUTLINED_FUNCTION_4 + 2828
11 SwiftUI                        0x1977948 OUTLINED_FUNCTION_4 + 4644
12 SwiftUI                        0xd6e9e8 objectdestroyTm + 22324
13 SwiftUI                        0xd6f0c4 objectdestroyTm + 24080
14 SwiftUI                        0xd6f1a0 objectdestroyTm + 24300
15 CoreFoundation                 0x2fc78 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
16 CoreFoundation                 0x2f640 ___CFXRegistrationPost_block_invoke + 88
17 CoreFoundation                 0x2f588 _CFXRegistrationPost + 440
18 CoreFoundation                 0x2ead8 _CFXNotificationPost + 724
19 Foundation                     0x2b7e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 92
20 OneSignalCore                  0x10d48 -[OneSignalUserDefaults saveDoubleForKey:withValue:] + 72
21 OneSignalFramework             0xda0c +[OneSignalTracker updateLastClosedTime] + 96
22 OneSignalFramework             0xd46c +[OneSignalTracker applicationBackgrounded] + 52
23 CoreFoundation                 0x2fc78 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
24 CoreFoundation                 0x2f640 ___CFXRegistrationPost_block_invoke + 88
25 CoreFoundation                 0x2f588 _CFXRegistrationPost + 440
26 CoreFoundation                 0x2ead8 _CFXNotificationPost + 724
27 Foundation                     0x2b7e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 92
28 UIKitCore                      0x5eca10 -[_UISceneLifecycleMonitor willResignActive] + 240
29 UIKitCore                      0x18fbb0 __111-[_UIWindowSceneFBSSceneLifecycleMonitor transitionToTargetState:fromState:withTransitionContext:preparations:]_block_invoke_5 + 332
30 UIKitCore                      0x18e988 _UIScenePerformActionsWithLifecycleActionMask + 112
31 UIKitCore                      0x2a5524 __111-[_UIWindowSceneFBSSceneLifecycleMonitor transitionToTargetState:fromState:withTransitionContext:preparations:]_block_invoke_4 + 156
32 UIKitCore                      0x13a1cc ___UISceneLifecycleSettingsUpdateBlockWithCanvasAndTransitionContext_block_invoke_2 + 296
33 UIKitCore                      0x139d00 -[_UIWindowSceneFBSSceneLifecycleMonitor transitionToTargetState:fromState:withTransitionContext:preparations:] + 680
34 UIKitCore                      0x139310 ___UISceneLifecycleSettingsUpdateBlockWithCanvasAndTransitionContext_block_invoke + 308
35 UIKitCore                      0x13900c __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 116
36 UIKitCore                      0x138f34 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 736
37 UIKitCore                      0x1387bc _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 224
38 UIKitCore                      0x13846c -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 316
39 UIKitCore                      0x4b787c __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.225 + 612
40 UIKitCore                      0x1375f0 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 216
41 UIKitCore                      0x137460 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 244
42 UIKitCore                      0x1372a0 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 336
43 FrontBoardServices             0xd99c -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 624
44 FrontBoardServices             0xd70c __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152
45 FrontBoardServices             0xd5a8 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 168
46 FrontBoardServices             0xd4c4 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 344
47 libdispatch.dylib              0x4300 _dispatch_client_callout + 20
48 libdispatch.dylib              0x7d48 _dispatch_block_invoke_direct + 284
49 FrontBoardServices             0x99ec __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52
50 FrontBoardServices             0x996c -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240
51 FrontBoardServices             0x9844 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28
52 CoreFoundation                 0x37acc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
53 CoreFoundation                 0x36d48 __CFRunLoopDoSource0 + 176
54 CoreFoundation                 0x3555c __CFRunLoopDoSources0 + 340
55 CoreFoundation                 0x34238 __CFRunLoopRun + 828
56 CoreFoundation                 0x33e18 CFRunLoopRunSpecific + 608
57 GraphicsServices               0x35ec GSEventRunModal + 164
58 UIKitCore                      0x22f2fc -[UIApplication _run] + 888
59 UIKitCore                      0x22e938 UIApplicationMain + 340
60 SwiftUI                        0x114d354 OUTLINED_FUNCTION_31 + 604
61 SwiftUI                        0x114d198 OUTLINED_FUNCTION_31 + 160
62 SwiftUI                        0xdca434 OUTLINED_FUNCTION_26 + 2196
63 App                            0x4b41d0 main + 52 (redacted)
64 ???                            0x1c3cf7d44 (Missing)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@danhalliday
Copy link

Looks related to my earlier report involving OneSignalUserDefaults: #1365. Is there any progress at all on reproducing and fixing these?

@nan-li
Copy link
Contributor

nan-li commented Mar 20, 2024

Hi @jakubpetrik thank you for reporting. I am not sure that this crash is due to OneSignal.

I see from the stack trace that the application is losing focus with willResignActive, causing OneSignal to save session time to NSUserDefaults.

The last call from OneSignal is this line which just calls NSUserDefaults method setDouble:forKey:, which I believe posts a notification to NSNotificationCenter.

20 OneSignalCore                  0x10d48 -[OneSignalUserDefaults saveDoubleForKey:withValue:] + 72

I did some digging online and came across this post that looks related.

The poster followed up with their root cause.

The root cause of this was that a ViewController that was dismissed by the time the application went into the background was still registered as an Observer of NSUserDefaults and when the app saved state that class was called and -> CRASH!

Do you have any components that are observing User Defaults?

@jakubpetrik
Copy link
Author

Hi @nan-li.

We only use AppStorage wrappers in our app (pure SwiftUI app). What's puzzling is that this issue started to appear only after adding OneSignal to our app and it seems to happen only in the production.

@danhalliday
Copy link

I am not sure that this crash is due to OneSignal.

This seems super unlikely to me. Sure a notification is posted to NSNotificationCenter to report the UserDefaults change, but who would be listening for a change on OneSignal’s defaults suite other than the OneSignal SDK?

Your linked post about the dismissed ViewController also doesn’t match any scenario that could be happening in my projects where I’m also seeing this crash. Nor did I see anything like this crash before upgrading to SDK V5, which suggests I don’t have problematic observation code hanging around.

It seems most likely to me that this is a concurrency issue in the OneSignal SDK just like the other recent crash reports appear to be.

@nan-li
Copy link
Contributor

nan-li commented Apr 16, 2024

Hi @jakubpetrik thank you for that update. That is informative as AppStorage works with UserDefaults and [OneSignalUserDefaults saveDoubleForKey:withValue:] is writing to UserDefaults.

A high-level search about AppStorage and UserDefaults took me to this thread.

This comment may be what is happening in your crash reported as observers are called listening to UserDefaults.

The AppStorage property wrapper uses KVO to observe UserDefaults. This makes writing to UserDefaults unsafe on non-main threads, even if the AppStorage is not using the same key as is being written. Any write to UserDefaults causes a lookup of all observers. If the AppStorage is deallocated during that lookup, there will be a crash.

It may be no other of your app dependencies are writing to UserDefaults at the end of the app lifecycle.

@nan-li
Copy link
Contributor

nan-li commented Apr 16, 2024

Hi @danhalliday

It seems most likely to me that this is a concurrency issue in the OneSignal SDK just like the other recent crash reports appear to be.

Your crash reports look like a different issue that the SDK is not handling well. We are working on the fix for those crashes.

@alphapokedex
Copy link

alphapokedex commented Apr 19, 2024

Got the same issue from firebase crashlytics
User's Iphone got stuck in one of the screens where OneSignal.login(id) got called by onesignal flutter sdk

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x3c20 objc_msgSend + 32
1  Foundation                     0x21354 _encodeObject + 180
2  Foundation                     0x210dc -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 460
3  Foundation                     0x4ffc0 -[NSArray(NSArray) encodeWithCoder:] + 588
4  Foundation                     0x2173c _encodeObject + 1180
5  Foundation                     0x6f12a0 +[NSKeyedArchiver archivedDataWithRootObject:] + 104
6  OneSignalCore                  0x112b4 -[OneSignalUserDefaults saveCodeableDataForKey:withValue:] + 88
7  OneSignalUser                  0x1a6a8 block_destroy_helper.32 + 16176
8  OneSignalUser                  0x837c __swift_project_boxed_opaque_existential_1 + 13672
9  OneSignalUser                  0x8640 __swift_project_boxed_opaque_existential_1 + 14380
10 OneSignalUser                  0x80e4 __swift_project_boxed_opaque_existential_1 + 13008
11 OneSignalUser                  0x8218 __swift_project_boxed_opaque_existential_1 + 13316
12 OneSignalFramework             0x7f34 +[OneSignal startNewSessionInternal] + 264
13 libdispatch.dylib              0x213c _dispatch_call_block_and_release + 32
14 libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
15 libdispatch.dylib              0x125a4 _dispatch_main_queue_drain + 988
16 libdispatch.dylib              0x121b8 _dispatch_main_queue_callback_4CF + 44
17 CoreFoundation                 0x3751c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
18 CoreFoundation                 0x34218 __CFRunLoopRun + 1996
19 CoreFoundation                 0x33968 CFRunLoopRunSpecific + 608
20 GraphicsServices               0x34e0 GSEventRunModal + 164
21 UIKitCore                      0x22aedc -[UIApplication _run] + 888
22 UIKitCore                      0x22a518 UIApplicationMain + 340
23 Runner                         0x8d20 main + 7 (AppDelegate.swift:7)
24 ???                            0x1c1702d84 (Missing)

@nan-li
Copy link
Contributor

nan-li commented May 15, 2024

Hi @jakubpetrik, checking in on this issue for you?

Hi @alphapokedex, your stack trace looks like this post: #1409. We released a fix for this crash in Release 5.1.6. Please update and let us know if your crashes are resolved, or what crashes are still ongoing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants