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

Random crash when getTokens is called: Attempted to dereference garbage pointer

Open mauronate opened this issue 2 years ago • 6 comments

Describe the bug This bug was reported from our error monitoring system Sentry, it's an attempted to deference garbage pointer kind of issue, and seems to be happening when the function getTokens is called, I will provide here two different stack traces of the error, in the first one in particular the issue seems to be happening at line 51 of the AWSMobileClient+Tokens file.

To Reproduce Occurs Randomly

Observed Behavior Crash

Expected Behavior The get tokens function is called succesfully

Stack Trace

Stack trace 1


OS Version: iOS 15.5 (19F77)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: BUS_NOOP at 0x0061007200650070
Crashed Thread: 12

Application Specific Information:
Exception 1, Code 6619248, Subcode 8 >
Attempted to dereference garbage pointer 0x61007200650070.

Thread 12 Crashed:
0   libobjc.A.dylib                 0x3345499c8         objc_retain
1   AWSMobileClient                 0x104cb5f88         [inlined] Array._getElement
2   AWSMobileClient                 0x104cb5f88         Array.subscript.getter
3   AWSMobileClient                 0x104cb613c         AWSMobileClient.getTokens (AWSMobileClient+Tokens.swift:51)
4   AWSMobileClient                 0x104cb5f14         thunk for closure
5   Foundation                      0x305acdfb8         __111+[__NSOperationInternalObserver _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_2
6   libdispatch.dylib               0x302447e68         _dispatch_call_block_and_release
7   libdispatch.dylib               0x302449a2c         _dispatch_client_callout
8   libdispatch.dylib               0x30244cb40         _dispatch_queue_override_invoke
9   libdispatch.dylib               0x30245b160         _dispatch_root_queue_drain
10  libdispatch.dylib               0x30245b968         _dispatch_worker_thread2
11  libsystem_pthread.dylib         0x3e4e4307c         _pthread_wqthread

Thread 0
0   libswiftCore.dylib              0x30c3b89a0         swift_getObjectType
1   libswiftCore.dylib              0x30c022880         [inlined] _bridgeAnyObjectToAny
2   libswiftCore.dylib              0x30c022880         _bridgeAnyObjectToAny
3   libswiftFoundation.dylib        0x30ba71050         NSURLSession.DataTaskPublisher.Inner.request
4   libswiftFoundation.dylib        0x30ba719cc         NSURLSession.DataTaskPublisher.Inner<T>
5   Combine                         0x332c5cda0         Publishers.FlatMap.Outer.receiveInner
6   Combine                         0x332c60684         Publishers.FlatMap.Outer.Side.receive
7   libswiftFoundation.dylib        0x30ba708c0         NSURLSession.DataTaskPublisher.receive<T>
8   Combine                         0x332c5edb0         Publishers.MapError.receive<T>
9   Combine                         0x332c61d7c         Publishers.FlatMap.Outer.receive
10  Combine                         0x332c65d2c         Publishers.FlatMap<T>.Outer<T>
11  Combine                         0x332c73748         Publishers.FlatMap.Outer.receiveInner
12  Combine                         0x332c61e00         Publishers.FlatMap.Outer.Side.receive
13  Combine                         0x332c73748         Publishers.FlatMap.Outer.receiveInner
14  Combine                         0x332c61e00         Publishers.FlatMap.Outer.Side.receive
15  Combine                         0x332c942a8         Just.Inner.request
16  Combine                         0x332c8b280         Just<T>.Inner<T>
17  Combine                         0x332c5cda0         Publishers.FlatMap.Outer.receiveInner
18  Combine                         0x332c60684         Publishers.FlatMap.Outer.Side.receive
19  Combine                         0x332c5d5c4         Just.receive<T>
20  Combine                         0x332c7adb0         Deferred.receive<T>
21  Combine                         0x332c8f680         Publishers.SetFailureType.receive<T>
22  Combine                         0x332c810e0         PublisherBox.receive<T>
23  Combine                         0x332c5ceb8         AnyPublisher.receive<T>
24  Combine                         0x332c61d7c         Publishers.FlatMap.Outer.receive
25  Combine                         0x332c65d2c         Publishers.FlatMap<T>.Outer<T>
26  Combine                         0x332c73748         Publishers.FlatMap.Outer.receiveInner
27  Combine                         0x332c61e00         Publishers.FlatMap.Outer.Side.receive
28  Combine                         0x332c73748         Publishers.FlatMap.Outer.receiveInner
29  Combine                         0x332c61e00         Publishers.FlatMap.Outer.Side.receive
30  Combine                         0x332c6c80c         Result.Publisher.Inner.request
31  Combine                         0x332c6ea14         Result<T>.Publisher.Inner<T>
32  Combine                         0x332c5cda0         Publishers.FlatMap.Outer.receiveInner
33  Combine                         0x332c60684         Publishers.FlatMap.Outer.Side.receive
34  Combine                         0x332c69cb8         Result.Publisher.receive<T>
35  Combine                         0x332c810e0         PublisherBox.receive<T>
36  Combine                         0x332c5ceb8         AnyPublisher.receive<T>
37  Combine                         0x332c61d7c         Publishers.FlatMap.Outer.receive
38  Combine                         0x332c65d2c         Publishers.FlatMap<T>.Outer<T>
39  Combine                         0x332c6c9f8         Publishers.ReceiveOn.Inner.receive
40  libswiftDispatch.dylib          0x336261c00         thunk for closure
41  libdispatch.dylib               0x302447e68         _dispatch_call_block_and_release
42  libdispatch.dylib               0x302449a2c         _dispatch_client_callout
43  libdispatch.dylib               0x302457f44         _dispatch_main_queue_drain
44  libdispatch.dylib               0x302457b94         _dispatch_main_queue_callback_4CF
45  CoreFoundation                  0x302a9d7fc         __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
46  CoreFoundation                  0x302a57700         __CFRunLoopRun
47  CoreFoundation                  0x302a6abc4         CFRunLoopRunSpecific
48  GraphicsServices                0x33acef370         GSEventRunModal
49  UIKitCore                       0x307854644         -[UIApplication _run]
50  UIKitCore                       0x3075d5d8c         UIApplicationMain
51  nate.native.ios                 0x20414690c         main (main.swift:13)
52  <unknown>                       0x1048e9ce4         <redacted>

Thread 1
0   libsystem_kernel.dylib          0x371fe9a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e4e43104         _pthread_wqthread

Thread 2 name: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib          0x371fe94a0         mach_msg_trap
1   libsystem_kernel.dylib          0x371fe9ae0         mach_msg
2   CoreFoundation                  0x302a52d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x302a571b8         __CFRunLoopRun
4   CoreFoundation                  0x302a6abc4         CFRunLoopRunSpecific
5   Foundation                      0x305a4d460         -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6   Foundation                      0x305a8ee28         -[NSRunLoop(NSRunLoop) runUntilDate:]
7   UIKitCore                       0x3077ce76c         -[UIEventFetcher threadMain]
8   Foundation                      0x305a9d438         __NSThread__start__
9   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 3
0   libsystem_kernel.dylib          0x371fe9a2c         __semwait_signal
1   libsystem_c.dylib               0x318d4f0e0         nanosleep
2   libsystem_c.dylib               0x318d63384         sleep
3   Sentry                          0x106a25888         monitorCachedData (SentryCrashCachedData.c:144)
4   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 4 name: SentryCrash Exception Handler (Secondary)
0   libsystem_kernel.dylib          0x371fe94a0         mach_msg_trap
1   libsystem_kernel.dylib          0x371fe9ae0         mach_msg
2   Sentry                          0x106a3291c         handleExceptions (SentryCrashMonitor_MachException.c:266)
3   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 6 name: io.sentry.anr-tracker
0   libsystem_kernel.dylib          0x371fe9a2c         __semwait_signal
1   libsystem_c.dylib               0x318d4f0e0         nanosleep
2   Foundation                      0x305aafd04         +[NSThread sleepForTimeInterval:]
3   Sentry                          0x106a189f8         -[SentryANRTracker detectANRs] (SentryANRTracker.m:66)
4   Foundation                      0x305a9d438         __NSThread__start__
5   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 7 name: GCDAsyncSocket-CFStream
0   libsystem_kernel.dylib          0x371fe94a0         mach_msg_trap
1   libsystem_kernel.dylib          0x371fe9ae0         mach_msg
2   CoreFoundation                  0x302a52d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x302a571b8         __CFRunLoopRun
4   CoreFoundation                  0x302a6abc4         CFRunLoopRunSpecific
5   Foundation                      0x305a4d460         -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6   CocoaAsyncSocket                0x104baaf70         +[GCDAsyncSocket cfstreamThread:] (GCDAsyncSocket.m:7686)
7   Foundation                      0x305a9d438         __NSThread__start__
8   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 8 name: com.apple.NSURLConnectionLoader
0   libsystem_kernel.dylib          0x371fe94a0         mach_msg_trap
1   libsystem_kernel.dylib          0x371fe9ae0         mach_msg
2   CoreFoundation                  0x302a52d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x302a571b8         __CFRunLoopRun
4   CoreFoundation                  0x302a6abc4         CFRunLoopRunSpecific
5   CFNetwork                       0x303d02238         _CFURLStorageSessionDisableCache
6   Foundation                      0x305a9d438         __NSThread__start__
7   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 9 name: com.apple.CFSocket.private
0   libsystem_kernel.dylib          0x371fea164         __select
1   CoreFoundation                  0x302af6b64         __CFSocketManager
2   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 10 name: AVAudioSession Notify Thread
0   libsystem_kernel.dylib          0x371fe94a0         mach_msg_trap
1   libsystem_kernel.dylib          0x371fe9ae0         mach_msg
2   CoreFoundation                  0x302a52d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x302a571b8         __CFRunLoopRun
4   CoreFoundation                  0x302a6abc4         CFRunLoopRunSpecific
5   AudioSession                    0x31569af00         CADeprecated::GenericRunLoopThread::Entry
6   AudioSession                    0x3156a48ec         CADeprecated::CAPThread::Entry
7   libsystem_pthread.dylib         0x3e4e439a8         _pthread_start

Thread 11
0   libsystem_pthread.dylib         0x3e4e42e54         start_wqthread

Thread 12 Crashed:
0   libobjc.A.dylib                 0x3345499c8         objc_retain
1   AWSMobileClient                 0x104cb5f88         [inlined] Array._getElement
2   AWSMobileClient                 0x104cb5f88         Array.subscript.getter
3   AWSMobileClient                 0x104cb613c         AWSMobileClient.getTokens (AWSMobileClient+Tokens.swift:51)
4   AWSMobileClient                 0x104cb5f14         thunk for closure
5   Foundation                      0x305acdfb8         __111+[__NSOperationInternalObserver _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_2
6   libdispatch.dylib               0x302447e68         _dispatch_call_block_and_release
7   libdispatch.dylib               0x302449a2c         _dispatch_client_callout
8   libdispatch.dylib               0x30244cb40         _dispatch_queue_override_invoke
9   libdispatch.dylib               0x30245b160         _dispatch_root_queue_drain
10  libdispatch.dylib               0x30245b968         _dispatch_worker_thread2
11  libsystem_pthread.dylib         0x3e4e4307c         _pthread_wqthread

Thread 13
0   libsystem_pthread.dylib         0x3e4e42e54         start_wqthread

Thread 14
0   libdispatch.dylib               0x302451018         _dispatch_lane_serial_drain
1   libdispatch.dylib               0x302451120         _dispatch_lane_serial_drain
2   libdispatch.dylib               0x302451c7c         _dispatch_lane_invoke
3   libdispatch.dylib               0x30245c4fc         _dispatch_workloop_worker_thread
4   libsystem_pthread.dylib         0x3e4e430b8         _pthread_wqthread



EOF

Stack trace 2:

OS Version: iOS 15.5 (19F77)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: BUS_NOOP at 0x000000927d7b68b0
Crashed Thread: 1

Application Specific Information:
Exception 1, Code 2105239728, Subcode 8 >
Attempted to dereference garbage pointer 0x927d7b68b0.

Thread 1 Crashed:
0   libswiftCore.dylib              0x3365ba40c         _swift_release_dealloc
1   AWSMobileClient                 0x1037ca30c         [inlined] _ArrayBuffer._consumeAndCreateNew
2   AWSMobileClient                 0x1037ca30c         _ArrayBuffer._consumeAndCreateNew
3   AWSMobileClient                 0x1037ca1b4         Array._makeMutableAndUnique
4   AWSMobileClient                 0x1037c9f14         thunk for closure
5   Foundation                      0x32fd0dfb8         __111+[__NSOperationInternalObserver _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_2
6   libdispatch.dylib               0x32c687e68         _dispatch_call_block_and_release
7   libdispatch.dylib               0x32c689a2c         _dispatch_client_callout
8   libdispatch.dylib               0x32c68cb40         _dispatch_queue_override_invoke
9   libdispatch.dylib               0x32c69b160         _dispatch_root_queue_drain
10  libdispatch.dylib               0x32c69b968         _dispatch_worker_thread2
11  libsystem_pthread.dylib         0x40f08307c         _pthread_wqthread

Thread 0
0   libsystem_platform.dylib        0x40f072fc4         _platform_strlen
1   Foundation                      0x32fce8338         -[NSXPCEncoder _encodeInvocation:isReply:into:]
2   Foundation                      0x32fcb98b8         -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]
3   CoreFoundation                  0x32ccb9c18         ___forwarding___
4   CoreFoundation                  0x32ccb8f6c         __forwarding_prep_0___
5   CoreFoundation                  0x32ccb6830         __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
6   CoreFoundation                  0x32cd52fd0         ___CFXRegistrationPost_block_invoke
7   CoreFoundation                  0x32cd261cc         _CFXRegistrationPost
8   CoreFoundation                  0x32cccc8a8         _CFXNotificationPost
9   Foundation                      0x32fc8f750         -[NSNotificationCenter postNotificationName:object:userInfo:]
10  UIKitCore                       0x33185002c         -[UIApplication _stopDeactivatingForReason:]
11  UIKitCore                       0x331772344         __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2
12  UIKitCore                       0x33172d3b0         _UIScenePerformActionsWithLifecycleActionMask
13  UIKitCore                       0x331857d8c         __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke
14  UIKitCore                       0x331977a9c         -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:]
15  UIKitCore                       0x331bb6760         -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
16  UIKitCore                       0x331b41d10         -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:]
17  UIKitCore                       0x33172e19c         __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke
18  UIKitCore                       0x3317ee0d4         +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:]
19  UIKitCore                       0x3317300a0         _UISceneSettingsDiffActionPerformChangesWithTransitionContext
20  UIKitCore                       0x33181a240         -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]
21  UIKitCore                       0x331c9ee5c         __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.615
22  UIKitCore                       0x33175e480         -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:]
23  UIKitCore                       0x3317a1cc0         -[UIScene scene:didUpdateWithDiff:transitionContext:completion:]
24  UIKitCore                       0x33172c034         -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:]
25  FrontBoardServices              0x35118ce14         -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:]
26  FrontBoardServices              0x3511a5138         __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2
27  FrontBoardServices              0x35118a304         -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
28  FrontBoardServices              0x351190820         __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke
29  libdispatch.dylib               0x32c689a2c         _dispatch_client_callout
30  libdispatch.dylib               0x32c68d4dc         _dispatch_block_invoke_direct
31  FrontBoardServices              0x35118bc6c         __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
32  FrontBoardServices              0x35118b03c         -[FBSSerialQueue _targetQueue_performNextIfPossible]
33  FrontBoardServices              0x35118f6fc         -[FBSSerialQueue _performNextFromRunLoopSource]
34  CoreFoundation                  0x32cd47410         __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
35  CoreFoundation                  0x32cd5819c         __CFRunLoopDoSource0
36  CoreFoundation                  0x32cc91690         __CFRunLoopDoSources0
37  CoreFoundation                  0x32cc97058         __CFRunLoopRun
38  CoreFoundation                  0x32ccaabc4         CFRunLoopRunSpecific
39  GraphicsServices                0x364f2f370         GSEventRunModal
40  UIKitCore                       0x331a94644         -[UIApplication _run]
41  UIKitCore                       0x331815d8c         UIApplicationMain
42  nate.native.ios                 0x2029ae90c         main (main.swift:13)
43  <unknown>                       0x103029ce4         <redacted>

Thread 1 Crashed:
0   libswiftCore.dylib              0x3365ba40c         _swift_release_dealloc
1   AWSMobileClient                 0x1037ca30c         [inlined] _ArrayBuffer._consumeAndCreateNew
2   AWSMobileClient                 0x1037ca30c         _ArrayBuffer._consumeAndCreateNew
3   AWSMobileClient                 0x1037ca1b4         Array._makeMutableAndUnique
4   AWSMobileClient                 0x1037c9f14         thunk for closure
5   Foundation                      0x32fd0dfb8         __111+[__NSOperationInternalObserver _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_2
6   libdispatch.dylib               0x32c687e68         _dispatch_call_block_and_release
7   libdispatch.dylib               0x32c689a2c         _dispatch_client_callout
8   libdispatch.dylib               0x32c68cb40         _dispatch_queue_override_invoke
9   libdispatch.dylib               0x32c69b160         _dispatch_root_queue_drain
10  libdispatch.dylib               0x32c69b968         _dispatch_worker_thread2
11  libsystem_pthread.dylib         0x40f08307c         _pthread_wqthread

Thread 2
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread

Thread 3
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread

Thread 4
0   libsystem_pthread.dylib         0x40f082e54         start_wqthread

Thread 5 name: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib          0x39c2294a0         mach_msg_trap
1   libsystem_kernel.dylib          0x39c229ae0         mach_msg
2   CoreFoundation                  0x32cc92d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x32cc971b8         __CFRunLoopRun
4   CoreFoundation                  0x32ccaabc4         CFRunLoopRunSpecific
5   Foundation                      0x32fc8d460         -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6   Foundation                      0x32fccee28         -[NSRunLoop(NSRunLoop) runUntilDate:]
7   UIKitCore                       0x331a0e76c         -[UIEventFetcher threadMain]
8   Foundation                      0x32fcdd438         __NSThread__start__
9   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 6
0   libsystem_kernel.dylib          0x39c229a2c         __semwait_signal
1   libsystem_c.dylib               0x342f8f0e0         nanosleep
2   libsystem_c.dylib               0x342fa3384         sleep
3   Sentry                          0x1064bd888         monitorCachedData (SentryCrashCachedData.c:144)
4   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 7 name: SentryCrash Exception Handler (Secondary)
0   libsystem_kernel.dylib          0x39c2294a0         mach_msg_trap
1   libsystem_kernel.dylib          0x39c229ae0         mach_msg
2   Sentry                          0x1064ca91c         handleExceptions (SentryCrashMonitor_MachException.c:266)
3   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 9 name: io.sentry.anr-tracker
0   libsystem_kernel.dylib          0x39c229a2c         __semwait_signal
1   libsystem_c.dylib               0x342f8f0e0         nanosleep
2   Foundation                      0x32fcefd04         +[NSThread sleepForTimeInterval:]
3   Sentry                          0x1064b09f8         -[SentryANRTracker detectANRs] (SentryANRTracker.m:66)
4   Foundation                      0x32fcdd438         __NSThread__start__
5   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 10
0   CoreFoundation                  0x32ccd4544         CFDictionaryCreateMutable
1   Security                        0x33ed3a7c8         SecCFDictionaryCOWGetMutable
2   Security                        0x33ed3ab30         SecItemCopyMatching
3   FraudForce                      0x107a0f93c         czsiSymbolZeroOne
4   FraudForce                      0x107a0fc30         czsiSymbolZeroOne
5   FraudForce                      0x107a0fde0         czsiSymbolZeroOne
6   FraudForce                      0x107a0ef98         czsiSymbolZeroOne
7   FraudForce                      0x107a0c2ec         czsiSymbolZeroOne
8   Foundation                      0x32fcc5c18         __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
9   Foundation                      0x32fcd7f90         -[NSBlockOperation main]
10  Foundation                      0x32fcb0210         __NSOPERATION_IS_INVOKING_MAIN__
11  Foundation                      0x32fcc15d8         -[NSOperation start]
12  Foundation                      0x32fcc4c64         __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__
13  Foundation                      0x32fcd2e0c         __NSOQSchedule_f
14  libdispatch.dylib               0x32c69882c         _dispatch_block_async_invoke2
15  libdispatch.dylib               0x32c689a2c         _dispatch_client_callout
16  libdispatch.dylib               0x32c68cee8         _dispatch_continuation_pop
17  libdispatch.dylib               0x32c68c554         _dispatch_async_redirect_invoke
18  libdispatch.dylib               0x32c69b160         _dispatch_root_queue_drain
19  libdispatch.dylib               0x32c69b968         _dispatch_worker_thread2
20  libsystem_pthread.dylib         0x40f08307c         _pthread_wqthread

Thread 11 name: GCDAsyncSocket-CFStream
0   libsystem_kernel.dylib          0x39c2294a0         mach_msg_trap
1   libsystem_kernel.dylib          0x39c229ae0         mach_msg
2   CoreFoundation                  0x32cc92d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x32cc971b8         __CFRunLoopRun
4   CoreFoundation                  0x32ccaabc4         CFRunLoopRunSpecific
5   Foundation                      0x32fc8d460         -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6   CocoaAsyncSocket                0x10389ef70         +[GCDAsyncSocket cfstreamThread:] (GCDAsyncSocket.m:7686)
7   Foundation                      0x32fcdd438         __NSThread__start__
8   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 12 name: com.apple.NSURLConnectionLoader
0   libsystem_kernel.dylib          0x39c2294a0         mach_msg_trap
1   libsystem_kernel.dylib          0x39c229ae0         mach_msg
2   CoreFoundation                  0x32cc92d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x32cc971b8         __CFRunLoopRun
4   CoreFoundation                  0x32ccaabc4         CFRunLoopRunSpecific
5   CFNetwork                       0x32df42238         _CFURLStorageSessionDisableCache
6   Foundation                      0x32fcdd438         __NSThread__start__
7   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 13 name: com.apple.CFSocket.private
0   libsystem_kernel.dylib          0x39c22a164         __select
1   CoreFoundation                  0x32cd36b64         __CFSocketManager
2   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 14
0   libsystem_kernel.dylib          0x39c22d3e4         __unlink
1   libsystem_kernel.dylib          0x39c2313a8         unlink
2   CFNetwork                       0x32df5a044         __CFTubeSetTubeTypeNotifier
3   CFNetwork                       0x32dda872c         CFHTTPCookieGetExpirationTime
4   libdispatch.dylib               0x32c69882c         _dispatch_block_async_invoke2
5   libdispatch.dylib               0x32c689a2c         _dispatch_client_callout
6   libdispatch.dylib               0x32c691120         _dispatch_lane_serial_drain
7   libdispatch.dylib               0x32c691cb0         _dispatch_lane_invoke
8   libdispatch.dylib               0x32c69c4fc         _dispatch_workloop_worker_thread
9   libsystem_pthread.dylib         0x40f0830b8         _pthread_wqthread

Thread 15 name: AVAudioSession Notify Thread
0   libsystem_kernel.dylib          0x39c2294a0         mach_msg_trap
1   libsystem_kernel.dylib          0x39c229ae0         mach_msg
2   CoreFoundation                  0x32cc92d2c         __CFRunLoopServiceMachPort
3   CoreFoundation                  0x32cc971b8         __CFRunLoopRun
4   CoreFoundation                  0x32ccaabc4         CFRunLoopRunSpecific
5   AudioSession                    0x33f8daf00         CADeprecated::GenericRunLoopThread::Entry
6   AudioSession                    0x33f8e48ec         CADeprecated::CAPThread::Entry
7   libsystem_pthread.dylib         0x40f0839a8         _pthread_start

Thread 16
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread

Thread 17
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread

Thread 18
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread

Thread 19
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread

Thread 20
0   libsystem_kernel.dylib          0x39c229a74         __workq_kernreturn
1   libsystem_pthread.dylib         0x40f083104         _pthread_wqthread



EOF

Code Snippet line 51 of the AWSMobileClient+Tokens file inside the getTokens function, here are the first 62 lines of the file in the version we are currently using:

//
// Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//

import Foundation
import AWSCore

public typealias TokenCompletion = (Tokens?, Error?) -> Void

extension AWSMobileClient {

    /// Returns cached UserPools auth JWT tokens if valid.
    /// If the `idToken` is not valid, and a refresh token is available, refresh token is used to get a new `idToken`.
    /// If there is no refresh token and the user is signed in, a notification is dispatched to indicate requirement of user to re-signin.
    /// The call to wait will be synchronized so that if multiple threads call this method, they will block till the first thread gets the token.
    ///
    /// - Parameter completionHandler: Tokens if available, else error.
    public func getTokens(_ completionHandler: @escaping TokenCompletion) {

        switch self.federationProvider {

        case .userPools:
            AWSMobileClientLogging.verbose("Adding FetchUserPoolTokensOperation operation")
            let operation = FetchUserPoolTokensOperation(completion: completionHandler)
            operation.delegate = self
            operation.completionBlock = { [weak self] in
                guard let index = self?.tokenOperations.firstIndex(of: operation) else {return}
                self?.tokenOperations.remove(at: index)
            }
            tokenOperations.append(operation)
            tokenFetchOperationQueue.addOperation(operation)

        case .hostedUI:
            AWSMobileClientLogging.verbose("Invoking hostedUI getTokens")
            let operation = FetchUserPoolTokensOperation(
                userPool: AWSCognitoAuth(forKey: AWSMobileClientConstants.CognitoAuthRegistrationKey),
                completion: completionHandler)
            operation.delegate = self
            operation.completionBlock = { [weak self] in
                guard let index = self?.tokenOperations.firstIndex(of: operation) else {return}
                self?.tokenOperations.remove(at: index)
            }
            tokenOperations.append(operation)
            tokenFetchOperationQueue.addOperation(operation)
        default:
            let message = AWSMobileClientConstants.notSignedInMessage
            let error = AWSMobileClientError.notSignedIn(message: message)
            completionHandler(nil, error)
        }
    }
}

Areas of the SDK you are using (AWSMobileClient, Cognito, Pinpoint, IoT, etc)? AWSMobileClient

Environment(please complete the following information):

  • AWS SDK 2.27.10 installed through cocoapods
  • Xcode 13.3.1

Device Information (please complete the following information): Happens on all different kinds of iOS devices and seems to be happening from iOS 14.7.1 to 15.5

mauronate avatar Jul 18 '22 13:07 mauronate

@mauronate There was a recent fix released around this in 2.27.12. Can you please use the latest version and verify if this still happens.

harsh62 avatar Jul 18 '22 16:07 harsh62

Hello. I use the latest 2.27.13 version and I still have this early crash related to AWSMobileClient getTokens. Here's my stack trace:

Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x99288 __exceptionPreprocess 1 libobjc.A.dylib 0x16744 objc_exception_throw 2 Foundation 0x143354 -[NSConcreteHashTable rehash] 3 Foundation 0x1da54 hashProbe 4 Foundation 0x20b64 -[NSConcreteHashTable addObject:] 5 AWSMobileClientXCF 0x38d54 AWSMobileClient.getTokens(_:) + 33 (AWSMobileClient+Tokens.swift:33) 6 Project 0x27755c specialized JWTAuthenticationServiceImpl.getToken(completion:) () 7 Project 0x270c20 JWTAuthenticationServiceImpl.retryTokenRequests() () 8 Project 0x2715fc @objc JWTAuthenticationServiceImpl.retryTokenRequests() () 9 Foundation 0x330ec __NSFireTimer 10 CoreFoundation 0xae678 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION 11 CoreFoundation 0x32654 __CFRunLoopDoTimer 12 CoreFoundation 0x2ce00 __CFRunLoopDoTimers 13 CoreFoundation 0xb4b0 __CFRunLoopRun 14 CoreFoundation 0x1ebc8 CFRunLoopRunSpecific 15 GraphicsServices 0x1374 GSEventRunModal 16 UIKitCore 0x514b58 -[UIApplication _run] 17 UIKitCore 0x296090 UIApplicationMain 18 Coople 0x7180 main + 41 (AppDelegate.swift:41) 19 ??? 0x102f09da4 (Missing)

Hm, also I can see that it might be Firebase that crashes my app. But still it got tracked in Crashlytics as AWS crashes my app.

Crashed: com.google.firebase.crashlytics.ios.exception 0 AnalyticsService 0xc5ca8 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393) 1 AnalyticsService 0xc6088 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424) 2 AnalyticsService 0xd53e0 FIRCLSHandler + 34 (FIRCLSHandler.m:34) 3 AnalyticsService 0xd51c8 __FIRCLSExceptionRecord_block_invoke + 232 (FIRCLSException.mm:232) 4 libdispatch.dylib 0x3a30 _dispatch_client_callout + 20 5 libdispatch.dylib 0x12c90 _dispatch_lane_barrier_sync_invoke_and_complete + 56 6 AnalyticsService 0xd3fa8 FIRCLSExceptionRecord + 234 (FIRCLSException.mm:234) 7 AnalyticsService 0xd4c70 FIRCLSExceptionRecordNSException + 126 (FIRCLSException.mm:126) 8 AnalyticsService 0xd3ba8 FIRCLSTerminateHandler() + 398 (FIRCLSException.mm:398) 9 libc++abi.dylib 0x10f18 std::__terminate(void (*)()) + 20 10 libc++abi.dylib 0x13ebc __cxa_rethrow + 148 11 libobjc.A.dylib 0x186c0 objc_exception_rethrow + 44 12 CoreFoundation 0x1ecb4 CFRunLoopRunSpecific + 836 13 GraphicsServices 0x1374 GSEventRunModal + 164 14 UIKitCore 0x514b58 -[UIApplication _run] + 1100 15 UIKitCore 0x296090 UIApplicationMain + 364 16 Project 0x7180 main + 41 (AppDelegate.swift:41) 17 ??? 0x102f09da4 (Missing)

VadimRupets avatar Aug 02 '22 07:08 VadimRupets

Hi,

Any updates on this? We are also on the latest version 2.27.13 and are experiencing a lot of crashes with the getTokens function.

Thank you!

Here is a stack trace:

0 libobjc.A.dylib 0x66f8 objc_loadWeakRetained + 140
1 libobjc.A.dylib 0x66cc objc_loadWeakRetained + 96
2 libobjc.A.dylib 0x9dac objc_loadWeak + 20
3 Foundation 0xc0b0c -[NSConcreteHashTable hashGrow] + 140
4 Foundation 0x20bb4 -[NSConcreteHashTable addObject:] + 148
5 AWSMobileClientXCF 0x38d68 AWSMobileClient.getTokens(_:) + 624
6 {MyApp} 0x3912b0 $s14Authentication11AuthServiceC12getAWSTokens33_C66F4B88FE75905EB74EDD2F8C956523LLSSyYaKFyScCySSs5Error_pGXEfU_ + 196
7 libswift_Concurrency.dylib 0x68a8 $ss31withCheckedThrowingContinuation8function_xSS_yScCyxs5Error_pGXEtYaKlFySccyxsAC_pGXEfU_TA + 164
8 libswift_Concurrency.dylib 0x69bc $ss30withUnsafeThrowingContinuationyxySccyxs5Error_pGXEYaKlF + 224
9 libswift_Concurrency.dylib 0x3b7c8 swift::runJobInEstablishedExecutorContext(swift::Job*) + 240

klein-thibault avatar Aug 29 '22 13:08 klein-thibault

Thank you for the stack trace, I am guessing the issue might be due to multiple thread trying access the shared NSHashTable. Created this PR that might potentially fix the issue, will you be able to test this? https://github.com/aws-amplify/aws-sdk-ios/pull/4290

royjit avatar Aug 31 '22 15:08 royjit

@klein-thibault The latest SDK release has a potential fix for the issue. Could you please give it a try and let us know if you are still facing the issue?

Release: https://github.com/aws-amplify/aws-sdk-ios/releases/tag/2.28.0

harsh62 avatar Sep 16 '22 18:09 harsh62

Thank you @royjit @harsh62; we'll include the updated SDK in our next release and report back here.

klein-thibault avatar Sep 20 '22 17:09 klein-thibault

Closing the issue. Please reopen if the issue still persists

harsh62 avatar Sep 30 '22 15:09 harsh62

Seeing this on 2.28.0, 2.30.4 and 2.33.4

edit: to clarify, only reproducing the EXC_BAD_ACCESS when testing release builds.

ChadyG avatar Oct 09 '23 20:10 ChadyG