SessionWebSocketEngine iOS 18 crash

[Problem/Question]
We’re seeing some crashers come in on Line 123 of SessionWebSocketEngine, particularly with iOS 18 users.

Crashed: com.sendbird.core.networking.websocket.queue (QOS: UNSPECIFIED)
0 libobjc.A.dylib 0x9260 objc_loadWeakRetained + 180
1 SendbirdChatSDK 0x35fc3c closure #1 in SessionWebSocketEngine.listen() + 123 (SessionWebSocketEngine.swift:123)
2 Foundation 0x46c294 + 200
3 Foundation 0x46c404 + 84
4 Foundation 0x1c6bc + 24
5 Foundation 0x1c57c + 104
6 Foundation 0x1c378 + 16
7 Foundation 0x1a5c8 + 648
8 Foundation 0x92280 + 16
9 Foundation 0x91eb0 + 172
10 libdispatch.dylib 0x132e8 _dispatch_block_async_invoke2 + 148
11 libdispatch.dylib 0x40d0 _dispatch_client_callout + 20
12 libdispatch.dylib 0x7580 _dispatch_continuation_pop + 596
13 libdispatch.dylib 0x6bb0 _dispatch_async_redirect_invoke + 580
14 libdispatch.dylib 0x15d8c _dispatch_root_queue_drain + 392
15 libdispatch.dylib 0x16590 _dispatch_worker_thread2 + 156
16 libsystem_pthread.dylib 0x4c40 _pthread_wqthread + 228
17 libsystem_pthread.dylib 0x1488 start_wqthread + 8


// If problem, please fill out the below. If question, please delete.
[SDK Version]
4.21.5

[Reproduction Steps]
Can’t repro, but all instances are on iOS 18.

[Current impact]
This is currently our app’s largest crasher.

Hi @L4Rugger

This issue has been reported to our engineering team, and they will investigate it promptly.

@Miyoung_Han Any progress on fixing this? After updating Sendbird SDK’s to the latest version we started seeing a large number of crashes.

@Miyoung_Han Is there any progress for this crash?

@Priya_Gandhi @Mateusz_Bienias @L4Rugger
Thank you for waiting for our release. The fix has been released today. Please refers to the details below. cc` @Miyoung_Han

We want to update you regarding the Sendbird Chat iOS SDK crash issue, particularly on the objc_loadWeakRetained function. This issue was identified in the NSURLSessionWebSocketTask.receive(completionHandler:) method, where crashes occur during the transition of weak self to strong self inside our closure. The crash arises due to potential memory management issues within the WebSocket implementation of NSURLSession.

After a thorough investigation, we found that Apple’s internal mechanisms for managing weak references in this context might not handle deallocated objects as expected. Apple has previously noted concerns about using NSURLSession for WebSockets, as outlined in their technical note TN3151.

To address this issue, we have refactored the relevant code to utilize Swift Concurrency. This improves memory safety and eliminates reliance on weak references in the WebSocket message handling logic. Additionally, we have revised the lifecycle management of objects using safer alternatives to GCD.

Since these modifications affect the core of Sendbird’s WebSocket connection—essential for both service stability and pricing accuracy—the resolution required careful design and testing. We appreciate your understanding regarding the time taken to implement these changes.

Looking ahead, we are taking steps to further improve the stability of our SDK by reducing dependence on NSURLSessionfor WebSockets. Instead, we will leverage advanced Swift Concurrency.

Please feel free to reach out if you have any questions or need further clarification.