smithy-lang/smithy-swift

FoundationStreamBridge.open crashes sometimes on app launch

Closed this issue · 4 comments

Describe the bug

We use amplify-swift for auth in our app, which uses the packages aws-sdk-swift, which uses smithy-swift.

We get 1-2 crashes per day from FoundationStreamBridge.open that seem to happen immediately after launch (potentially even before any of our code runs). We are unable to reproduce the crash, and it happens on both iOS16 and iOS17. See below, noting "MyProject" is the app wrapper and "App" is our own Swift Package where all our code is written.

Expected Behavior

Our app should not crash on launch.

Current Behavior

OS Version: iOS 17.4.1 (21E236)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: SEGV_NOOP at 0x000000000000000c
Crashed Thread: 4

Application Specific Information:
Exception 1, Code 1, Subcode 12 >
KERN_INVALID_ADDRESS at 0xc.

Thread 4 Crashed:
0   CoreFoundation                  0x32d25bb30         CFRunLoopWakeUp
1   CoreFoundation                  0x32d25bb28         CFRunLoopWakeUp
2   Foundation                      0x32affdb94         -[NSThread _nq:]
3   Foundation                      0x32affd8ac         -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:]
4   Foundation                      0x32b01f0b8         -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:]
5   App                             0x10405fd50         FoundationStreamBridge.open
6   App                             0x10405de04         thunk for closure
7   libdispatch.dylib               0x33cfe8138         _dispatch_call_block_and_release
8   libdispatch.dylib               0x33cfe9dd0         _dispatch_client_callout
9   libdispatch.dylib               0x33cff13fc         _dispatch_lane_serial_drain
10  libdispatch.dylib               0x33cff1f2c         _dispatch_lane_invoke
11  libdispatch.dylib               0x33cffccb0         _dispatch_root_queue_drain_deferred_wlh
12  libdispatch.dylib               0x33cffc524         _dispatch_workloop_worker_thread
13  libsystem_pthread.dylib         0x3e51b7f1c         _pthread_wqthread

Thread 0
0   libsystem_kernel.dylib          0x3bdca9af8         mach_msg2_trap
1   libsystem_kernel.dylib          0x3bdca988c         mach_msg2_internal
2   libsystem_kernel.dylib          0x3bdca97a4         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3bdca95e4         mach_msg
4   CoreFoundation                  0x32d22a018         __CFRunLoopServiceMachPort
5   CoreFoundation                  0x32d227f00         __CFRunLoopRun
6   CoreFoundation                  0x32d227964         CFRunLoopRunSpecific
7   GraphicsServices                0x3b58434dc         GSEventRunModal
8   UIKitCore                       0x331916ed8         -[UIApplication _run]
9   UIKitCore                       0x331916514         UIApplicationMain
10  SwiftUI                         0x335e9b85c         OUTLINED_FUNCTION_39
11  SwiftUI                         0x335e9b6a4         OUTLINED_FUNCTION_39
12  SwiftUI                         0x335ab79f8         7SwiftUI4ViewRzlAA15ModifiedContentVyxAA30_EnvironmentKeyWritingModifierVySbGGAaBHPxAaBHD1__AgA0cI0HPyHCHCTm
13  MyProject                     0x202cd04e0         [inlined] MyProjectApp.$main
14  MyProject                     0x202cd04e0         main
15  <unknown>                       0x1c8592d84         <redacted>

Thread 1
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 2
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 3
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 4 Crashed:
0   CoreFoundation                  0x32d25bb30         CFRunLoopWakeUp
1   CoreFoundation                  0x32d25bb28         CFRunLoopWakeUp
2   Foundation                      0x32affdb94         -[NSThread _nq:]
3   Foundation                      0x32affd8ac         -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:]
4   Foundation                      0x32b01f0b8         -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:]
5   App                             0x10405fd50         FoundationStreamBridge.open
6   App                             0x10405de04         thunk for closure
7   libdispatch.dylib               0x33cfe8138         _dispatch_call_block_and_release
8   libdispatch.dylib               0x33cfe9dd0         _dispatch_client_callout
9   libdispatch.dylib               0x33cff13fc         _dispatch_lane_serial_drain
10  libdispatch.dylib               0x33cff1f2c         _dispatch_lane_invoke
11  libdispatch.dylib               0x33cffccb0         _dispatch_root_queue_drain_deferred_wlh
12  libdispatch.dylib               0x33cffc524         _dispatch_workloop_worker_thread
13  libsystem_pthread.dylib         0x3e51b7f1c         _pthread_wqthread

Thread 5
0   AppSSOCore                      0x3c343a2c0         __53+[SOInternalProtocols interfaceWithInternalProtocol:]_block_invoke
1   libdispatch.dylib               0x33cfe9dd0         _dispatch_client_callout
2   libdispatch.dylib               0x33cfeb650         _dispatch_once_callout
3   AppSSOCore                      0x3c3439540         +[SOInternalProtocols interfaceWithInternalProtocol:]
4   AppSSOCore                      0x3c3439138         -[SOServiceConnection _connectToService]
5   AppSSOCore                      0x3c3439064         -[SOServiceConnection initWithQueue:]
6   AppSSOCore                      0x3c3438fe4         -[SOClient init]
7   AppSSOCore                      0x3c3438f1c         -[SOConfigurationClient init]
8   AppSSOCore                      0x3c3438e3c         __38+[SOConfigurationClient defaultClient]_block_invoke
9   libdispatch.dylib               0x33cfe9dd0         _dispatch_client_callout
10  libdispatch.dylib               0x33cfeb650         _dispatch_once_callout
11  AppSSOCore                      0x3c3438c84         +[SOConfigurationClient defaultClient]
12  AppSSOCore                      0x3c3437d5c         +[SOAuthorizationCore _canPerformAuthorizationWithURL:responseCode:callerBundleIdentifier:useInternalExtensions:]
13  CFNetwork                       0x32f63ce78         CFHTTPCookieStorageUnscheduleFromRunLoop
14  CFNetwork                       0x32f4d3af4         CFURLProtectionSpaceReceivesCredentialSecurely
15  CFNetwork                       0x32f503bc8         CFURLDownloadStart
16  CFNetwork                       0x32f4715bc         _CFNetworkSetHSTSStoragePath
17  CFNetwork                       0x32f4712c8         _CFNetworkSetHSTSStoragePath
18  CFNetwork                       0x32f471180         _CFNetworkSetHSTSStoragePath
19  CFNetwork                       0x32f48fd74         CFHTTPMessageCopySerializedMessage
20  CFNetwork                       0x32f6d6858         estimatedPropertyListSize
21  libdispatch.dylib               0x33cfe8138         _dispatch_call_block_and_release
22  libdispatch.dylib               0x33cfe9dd0         _dispatch_client_callout
23  libdispatch.dylib               0x33cff13fc         _dispatch_lane_serial_drain
24  libdispatch.dylib               0x33cff1f60         _dispatch_lane_invoke
25  libdispatch.dylib               0x33cffccb0         _dispatch_root_queue_drain_deferred_wlh
26  libdispatch.dylib               0x33cffc524         _dispatch_workloop_worker_thread
27  libsystem_pthread.dylib         0x3e51b7f1c         _pthread_wqthread

Thread 6
0   libsystem_pthread.dylib         0x3e51b7fb8         start_wqthread

Thread 7 name: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib          0x3bdca9af8         mach_msg2_trap
1   libsystem_kernel.dylib          0x3bdca988c         mach_msg2_internal
2   libsystem_kernel.dylib          0x3bdca97a4         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3bdca95e4         mach_msg
4   CoreFoundation                  0x32d22a018         __CFRunLoopServiceMachPort
5   CoreFoundation                  0x32d227f00         __CFRunLoopRun
6   CoreFoundation                  0x32d227964         CFRunLoopRunSpecific
7   Foundation                      0x32af4d4a4         -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
8   Foundation                      0x32af774e4         -[NSRunLoop(NSRunLoop) runUntilDate:]
9   UIKitCore                       0x331879ac4         -[UIEventFetcher threadMain]
10  Foundation                      0x32afbea98         __NSThread__start__
11  libsystem_pthread.dylib         0x3e51b8a8c         _pthread_start

Thread 8
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 9
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 10
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 11
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 12
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 13
0   libsystem_kernel.dylib          0x3bdcb2084         __workq_kernreturn
1   libsystem_pthread.dylib         0x3e51b7f68         _pthread_wqthread

Thread 14
0   libsystem_kernel.dylib          0x3bdcaa2f8         __semwait_signal
1   libsystem_c.dylib               0x33d07de9c         nanosleep
2   libsystem_c.dylib               0x33d08c154         sleep
3   App                             0x104519178         monitorCachedData (SentryCrashCachedData.c:145)
4   libsystem_pthread.dylib         0x3e51b8a8c         _pthread_start

Thread 15 name: SentryCrash Exception Handler (Secondary)
0   libsystem_kernel.dylib          0x3bdca9af8         mach_msg2_trap
1   libsystem_kernel.dylib          0x3bdca988c         mach_msg2_internal
2   libsystem_kernel.dylib          0x3bdca97a4         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3bdca95e4         mach_msg
4   App                             0x104514f74         handleExceptions (SentryCrashMonitor_MachException.c:314)
5   libsystem_pthread.dylib         0x3e51b8a8c         _pthread_start

Thread 17 name: io.sentry.app-hang-tracker
0   libsystem_kernel.dylib          0x3bdcaa2f8         __semwait_signal
1   libsystem_c.dylib               0x33d07de9c         nanosleep
2   Foundation                      0x32b6726bc         +[NSThread sleepForTimeInterval:]
3   App                             0x1044a9404         -[SentryANRTracker detectANRs] (SentryANRTracker.m:105)
4   Foundation                      0x32afbea98         __NSThread__start__
5   libsystem_pthread.dylib         0x3e51b8a8c         _pthread_start

Thread 18
0   libsystem_kernel.dylib          0x3bdcaa49c         __psynch_cvwait
1   libsystem_pthread.dylib         0x3e51b758c         _pthread_cond_wait
2   App                             0x103fa538c         aws_condition_variable_wait (condition_variable.c:74)
3   App                             0x103f9a3b4         aws_condition_variable_wait_pred (condition_variable.c:16)
4   App                             0x103fa27b8         aws_background_logger_thread (log_channel.c:157)
5   App                             0x103fa7a00         thread_fn (thread.c:177)
6   libsystem_pthread.dylib         0x3e51b8a8c         _pthread_start

Thread 19
0   libsystem_kernel.dylib          0x3bdcb78cc         kevent
1   App                             0x103fb2c34         aws_event_loop_thread (kqueue_event_loop.c:876)
2   App                             0x103fa7a00         thread_fn (thread.c:177)
3   libsystem_pthread.dylib         0x3e51b8a8c         _pthread_start

Thread 4 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000100   x3: 0x0000000000000000
    x4: 0x00000000000120a8   x5: 0x0000000000002340   x6: 0x000000030157e220   x7: 0x0000000000000000
    x8: 0x0000000000000000   x9: 0x0000000000000000  x10: 0x0000000000000002  x11: 0x000000000000d142
   x12: 0x0000000000000001  x13: 0x0000010000000102  x14: 0x0000010000000202  x15: 0x00000002065e3fd8
   x16: 0x000000000000012d  x17: 0x00000002117454d0  x18: 0x0000000000000000  x19: 0x0000000302031a40
   x20: 0x0000000302031a50  x21: 0x000000030172c1b0  x22: 0x0000000000000000  x23: 0x000000020d0ffeb0
   x24: 0x000000020d108b80  x25: 0x000000030202c6c0  x26: 0x0000000000000001  x27: 0x0000000000000001
   x28: 0x000000020d108b80   fp: 0x000000016d35e520   lr: 0xd70a3a01a50a5b2c   sp: 0x000000016d35e3e0
    pc: 0x00000001a50a5b30 cpsr: 0x0000000080001000



EOF

Reproduction Steps

Unknown, the app seems to just crash immediately after a user launches it.

Possible Solution

As far as we can tell this crash only started happening when we updated from Amplify 2.25.4 to 2.27.0, which in turn seems to have updated aws-sdk-swift. It is very difficult to tell definitively what changed in relation to smith-swift there 😅

Additional Information/Context

No response

AWS SWIFT SDK version used

aws-sdk-swift 0.36.1 via Amplify 2.27.0

Compiler and Version used

Xcode 15.1, swift-tools-version 5.7

Operating System and version

macOS 14.2.1 (23C71)

Hi @maxchuquimia , thank you for your report. Extra thanks for the additional detail!

We haven't seen a crash of this type before, so we'll try to reproduce it. We may reach out if we need additional info. Once we have a fix for you, we'll post it here so you can update to it.

@maxchuquimia: Please update to amplify-swift 2.33.2 and see if that affects your crash rate.
https://github.com/aws-amplify/amplify-swift/releases/tag/2.33.2

We were unable to reproduce the crash you reported, but we refactored some HTTP client code in a way that should enhance stability.

Please let us know how this affects your crash rate. Thanks!

Cheers @jbelkins, will report back after we release!

@jbelkins This crash is no longer happening in versions of our app after updating, thank you!