iOS always crashes when deleting a channel (SBDMessageDatabase)

Problem:
The iOS app crashes whenever a channel is deleted regardless of whether it was deleted in the app or from the SendBird dashboard.

Steps to reproduce:

  1. Initialize SBD with SBDMain.initWithApplicationId() and then connect with SBDMain.connect()
  2. Fetch the user’s channels with SBDGroupChannelListQuery.loadNextPage()

Everything works as expected up to this point. I am fetching the channels I previously created perfectly fine.

  1. Delete the channel either with the iOS sdk or on the dashboard. The app will now crash

Throw Call Stack:
0 CoreFoundation 0x000000010fb2ffba __exceptionPreprocess + 242
1 libobjc.A.dylib 0x0000000119860ff5 objc_exception_throw + 48
2 SendBirdSDK 0x00000001157700d3 +[SBDMessageDatabase removeAllMessagesWithChannelUrls:] + 514
3 SendBirdSDK 0x000000011580d0ba -[SBDCommandProcessor processChannelDeleted:] + 357
4 SendBirdSDK 0x000000011580b293 -[SBDCommandProcessor processSystemEvent:sender:] + 676
5 SendBirdSDK 0x0000000115807294 -[SBDCommandProcessor processCommand:shouldHandleBlock:] + 511
6 SendBirdSDK 0x000000011575bae5 __103+[SBDMain connectWebSocketServerReconnect:userId:accessToken:sessionKey:fromOnError:completionHandler:]_block_invoke.423 + 197
7 SendBirdSDK 0x00000001157f1399 -[SBDWebSocketClient webSocket:didReceiveMessage:] + 376
8 SendBirdSDK 0x00000001157a3266 __35-[SBDSessionWebSocketEngine listen]_block_invoke_4 + 156
9 libdispatch.dylib 0x000000011c321578 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000011c32274e _dispatch_client_callout + 8
11 libdispatch.dylib 0x000000011c328f9a _dispatch_lane_serial_drain + 796
12 libdispatch.dylib 0x000000011c329c67 _dispatch_lane_invoke + 436
13 libdispatch.dylib 0x000000011c335a7a _dispatch_workloop_worker_thread + 872
14 libsystem_pthread.dylib 0x000000011c7f545d _pthread_wqthread + 314
15 libsystem_pthread.dylib 0x000000011c7f442f start_wqthread + 15

I believe the problem is in SBDMessageDatabase.removeAllMessagesWithChannelUrls()

The application is connected to the sendbird sdk through a websocket and when it tries to remove all the messages in the channel, the application crashes and throws the error: “Terminating app due to uncaught exception ‘Sendbird Exception’, reason: ‘Database error.’”

Please make an update to resolve this issue.

Thanks

@finchat could you tell me environment settings and version? thanks

Hi @Woo
I’m using the latest version of SendBird - 3.0.227
iOS Deployment Target - Tested with version 11.0 and 14.5
Tested with iPhone 11 simulator and physical iPhone 11

Please let me know if you need more info

Hi @Woo
I have more information:

SBDGroupChannel.sendUserMessage() is causing a crash as well. There is something very wrong with the database on the latest version.

I tried reverting back to version 3.0.216 and everything works as expected. I will be using this version for now.

local caching feature is included in latest version, I will check with exception handling. you can use 3.0.226

Do you mind to share the crash you experience on sendUsesrMessage too?

Yes, I can confirm 3.0.226 is working well.

Here’s the call stack for the crash:

2021-07-12 16:42:52.521997-0700 FinChat[13448:8276204] *** Terminating app due to uncaught exception ‘Sendbird Exception’, reason: ‘Database error.’
*** First throw call stack:
(
0 CoreFoundation 0x000000010c6abfba __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00000001162c1ff5 objc_exception_throw + 48
2 SendBirdSDK 0x00000001121f32ea +[SBDGroupChannelDatabase insertOrReplaceWithChannels:] + 512
3 SendBirdSDK 0x000000011222ea77 -[SBDChannelDataSource updateChannel:] + 173
4 SendBirdSDK 0x0000000112261cbe __48-[SBDCommandProcessor processNewMessage:sender:]_block_invoke_2 + 166
5 libdispatch.dylib 0x0000000118d82578 _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x0000000118d8374e _dispatch_client_callout + 8
7 libdispatch.dylib 0x0000000118d91b3f _dispatch_main_queue_callback_4CF + 1152
8 CoreFoundation 0x000000010c6198f8 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
9 CoreFoundation 0x000000010c614169 __CFRunLoopRun + 2781
10 CoreFoundation 0x000000010c6131a7 CFRunLoopRunSpecific + 567
11 GraphicsServices 0x000000011a930d85 GSEventRunModal + 139
12 UIKitCore 0x00000001220ba4df -[UIApplication _run] + 912
13 UIKitCore 0x00000001220bf39c UIApplicationMain + 101
14 FinChat 0x000000010af227a8 main + 56
15 libdyld.dylib 0x0000000118e11bbd start + 1
)
libc++abi: terminating with uncaught exception of type NSException

Got it. Please use 226 version until we release new version. (226 is enough for a while since local caching is still not GA)

@finchat
We have released the hotfix version.
Please update version to SendBirdSDK 3.0.228.