# SessionWebSocketEngine iOS 18 crash

**URL:** <https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127>\
**Category:** iOS\
**Created:** [September 26, 2024, 11:36pm UTC](https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127 "2024-09-26T23:36:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![L4Rugger](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@L4Rugger](https://community.sendbird.com/u/L4Rugger)\
**Post date:** [September 26, 2024, 11:36pm UTC](https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127/1 "2024-09-26T23:36:14Z")

</div>

**[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.

---

<div class="post-metadata">

**Author:** ![Miyoung\_Han](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/miyoung_han/32/183_2.png) [@Miyoung\_Han](https://community.sendbird.com/u/Miyoung_Han)\
**Post date:** [September 27, 2024, 1:09am UTC](https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127/2 "2024-09-27T01:09:36Z")

</div>

Hi @L4Rugger

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

---

<div class="post-metadata">

**Author:** ![Mateusz\_Bienias](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/mateusz_bienias/32/5561_2.png) [@Mateusz\_Bienias](https://community.sendbird.com/u/Mateusz_Bienias)\
**Post date:** [November 4, 2024, 3:14pm UTC](https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127/3 "2024-11-04T15:14:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Priya\_Gandhi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/priya_gandhi/32/5615_2.png) [@Priya\_Gandhi](https://community.sendbird.com/u/Priya_Gandhi)\
**Post date:** [December 9, 2024, 9:00pm UTC](https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127/4 "2024-12-09T21:00:41Z")

</div>

@Miyoung_Han Is there any progress for this crash?

---

<div class="post-metadata">

**Author:** ![Young\_Hwang](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/young_hwang/32/188_2.png) [@Young\_Hwang](https://community.sendbird.com/u/Young_Hwang)\
**Post date:** [December 19, 2024, 8:45am UTC](https://community.sendbird.com/t/sessionwebsocketengine-ios-18-crash/10127/5 "2024-12-19T08:45:28Z")

</div>

@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](https://developer.apple.com/documentation/technotes/tn3151-choosing-the-right-networking-api#WebSocket-alternatives).

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 `NSURLSession`for WebSockets. Instead, we will leverage advanced Swift Concurrency.

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