SendbirdSDK crashes when simultaneous calls to SBDMain.getTotalUnreadMessageCount are made

I updated the sendbird iOS framework to the latest version (v3.0.204) but it’s crashing when simultaneous calls to SBDMain.getTotalUnreadMessageCount are made. If I go back to my previous version everything works fine.

I’m getting this stack trace error:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x0000000108c16bf8 SendBirdSDK`-[SBDHTTPClient buildRequestWithType:body:](self=0x0000600001204460, _cmd="buildRequestWithType:body:", type=@"GET", body=0x0000000000000000) at SBDHTTPClient.m:500:27
    frame #1: 0x0000000108c16409 SendBirdSDK`-[SBDHTTPClient getUri:parameter:completionHandler:](self=0x0000600001204460, _cmd="getUri:parameter:completionHandler:", uri=@"/v3/users/(null)/unread_message_count", parameter=1 key/value pair, completionHandler=0x0000000108b1ce30) at SBDHTTPClient.m:424:36
    frame #2: 0x0000000108bd7157 SendBirdSDK`-[SBDPlatformAPIClient getTotalUnreadMessageCountWithUserId:channelCustomTypes:superChannelFilter:completionHandler:](self=0x0000600002108310, _cmd="getTotalUnreadMessageCountWithUserId:channelCustomTypes:superChannelFilter:completionHandler:", userId=0x0000000000000000, channelCustomTypes=0x0000000000000000, superChannelFilter=SBDGroupChannelSuperChannelFilterAll, completionHandler=0x0000000108b1ce30) at SBDPlatformAPIClient.m:2027:5
    frame #3: 0x0000000108b8b7be SendBirdSDK`-[SBDCoreAPIClient getTotalUnreadMessageChannelCustomTypes:superChannelFilter:completionHandler:](self=0x00006000021084c0, _cmd="getTotalUnreadMessageChannelCustomTypes:superChannelFilter:completionHandler:", channelCustomTypes=0x0000000000000000, superChannelFilter=SBDGroupChannelSuperChannelFilterAll, completionHandler=0x0000000108b1ce30) at SBDCoreAPIClient.m:840:5
    frame #4: 0x0000000108b1cdc4 SendBirdSDK`+[SBDMain getTotalUnreadMessageCountWithParams:completionHandler:](self=SBDMain, _cmd="getTotalUnreadMessageCountWithParams:completionHandler:", params=0x000060000233e6e0, completionHandler=0x0000000108ebe1b0) at SBDMain.m:2359:5
    frame #5: 0x0000000108b1cc0b SendBirdSDK`+[SBDMain getTotalUnreadMessageCountWithCompletionHandler:](self=SBDMain, _cmd="getTotalUnreadMessageCountWithCompletionHandler:", completionHandler=0x0000000108ebe1b0) at SBDMain.m:2349:5

Hi @odm I will investigate and get back to you as soon as possible! Thank you for the reporting

1 Like

It seems like SDK couldn’t get current user information properly at the time you call the method. Would you mind to check you call this method after connect: method? or is this happening 100% when you call this method? and you said you call the method simultaneously meaning you call the method multiple time concurrently?

This is happening 100% when I call this method twice (probably from multiple threads). To test it just make two calls one after the other and it will always crash. This same code didn’t crash with previous versions of the SDK.

I see, how do you call this method in multiple threads? (like GCD or NSOperation, etc) would you mind to share code snippet

GCD, but the crash can be triggered just by doing the same call twice like this:

SBDMain.getTotalUnreadMessageCount { (_, _) in }
SBDMain.getTotalUnreadMessageCount { (_, _) in }

I tried to reproduce it on sample code but it won’t crash :confused: I tried to run it on both main and background. I know it wouldn’t crash on previous version but I’m trying to find out why current user information couldn’t get retrieved. If you see the log /v3/users/(null)/unread_message_count indicating that SBDMain.getCurrentUser was somehow return nil at the time.

Probably is some race condition. I do sendbird authentication on background and then after a new app launch if it’s already logged in l call the getTotalUnreadMessageCount from other parts in the app so I could be that the getTotalUnreadMessageCount call is being done before auth but I would expect an error instead, not a crash :frowning:

1 Like

oh ok thats correct! It shouldn’t crash :sob: I already knew the source of crash, just wondering why current user is not get retrieved properly. Your last comment make sense to me now then. I am planning to release new version this Friday. Thanks for your patience!

2 Likes

No worries, thank you so much for your prompt response and support!

Any time! Thanks for quick reporting about the crash