Android C BLIPConnection.hh related crash

The Couchbase Lite 3.01 for Android C is crashing with the below stacktrace. The following warnings/error are logged before the crash:

{N8litecore9websocket16BuiltInWebSocketE#23} No response received after 10 sec -- disconnecting
{N8litecore9websocket16BuiltInWebSocketE#23} Unexpected or unclean socket disconnect! (reason=errno 0)
{Repl#22} Got LiteCore error: WebSocket error 1006, "connection closed abnormally"
{C4Replicator#13} Transient error (WebSocket error 1006, "connection closed abnormally"); attempt #2 in 2 sec...

The stack trace:

SIGSEGV Segmentation violation (invalid memory reference) 
    ../../../../../home/couchbase/jenkins/workspace/couchbase-lite-c-android/couchbase-lite-c/vendor/couchbase-lite-core/Networking/BLIP/BLIPConnection.hh:58 litecore::blip::Connection::delegate() const
    ../../../../../home/couchbase/jenkins/workspace/couchbase-lite-c-android/couchbase-lite-c/vendor/couchbase-lite-core/Networking/BLIP/BLIPConnection.cc:693 litecore::blip::Connection::gotTLSCertificate(fleece::slice)
    ../../../../../home/couchbase/jenkins/workspace/couchbase-lite-c-android/couchbase-lite-c/vendor/couchbase-lite-core/Networking/BLIP/BLIPConnection.cc:182 litecore::blip::BLIPIO::onWebSocketGotTLSCertificate(fleece::slice)
    ../../../../../home/couchbase/jenkins/workspace/couchbase-lite-c-android/couchbase-lite-c/vendor/couchbase-lite-core/Networking/BLIP/BLIPConnection.cc:-1 __cxx_global_var_init
    ../../../../../home/couchbase/jenkins/workspace/couchbase-lite-c-android/couchbase-lite-c/vendor/couchbase-lite-core/Networking/WebSockets/BuiltInWebSocket.cc:247 litecore::websocket::BuiltInWebSocket::_connectLoop()
    ../../../../../home/couchbase/jenkins/workspace/couchbase-lite-c-android/couchbase-lite-c/vendor/couchbase-lite-core/Networking/WebSockets/BuiltInWebSocket.cc:122 litecore::websocket::BuiltInWebSocket::_bgConnect()
    ../../../../../home/couchbase/jenkins/tools/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/type_traits:3442 _ZNSt6__ndk18__invokeIRMN8litecore9websocket16BuiltInWebSocketEFvvERPS3_JEvEEDTcldsdeclsr3std6__ndk1E7forwardIT0_Efp0_Efp_spclsr3std6__ndk1E7forwardIT1_Efp1_EEEOT_OS9_DpOSA_
    ../../../../../home/couchbase/jenkins/tools/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/functional:2770 _ZNSt6__ndk115__apply_functorIMN8litecore9websocket16BuiltInWebSocketEFvvENS_5tupleIJPS3_EEEJLm0EENS6_IJEEEEENS_13__bind_returnIT_T0_T2_Xsr22__is_valid_bind_returnISB_SC_SD_EE5valueEE4typeERSB_RSC_NS_15__tuple_indicesIJXspT1_EEEEOSD_
    ../../../../../home/couchbase/jenkins/tools/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/functional:2803 _ZNSt6__ndk16__bindIMN8litecore9websocket16BuiltInWebSocketEFvvEJPS3_EEclIJEEENS_13__bind_returnIS5_NS_5tupleIJS6_EEENSA_IJDpOT_EEEXsr22__is_valid_bind_returnIS5_SB_SF_EE5valueEE4typeESE_
    ../../../../../home/couchbase/jenkins/tools/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/type_traits:3501 _ZNSt6__ndk18__invokeIRZN8litecore9websocket16BuiltInWebSocket13awaitReadableEvE3$_2JEEEDTclclsr3std6__ndk1E7forwardIT_Efp_Espclsr3std6__ndk1E7forwardIT0_Efp0_EEEOS6_DpOS7_
    ../../../../../home/couchbase/jenkins/tools/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/thread:273 void std::__ndk1::__thread_execute<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct> >, std::__ndk1::__bind<void (litecore::websocket::BuiltInWebSocket::*)(), litecore::websocket::BuiltInWebSocket*>>(std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct> >, std::__ndk1::__bind<void (litecore::websocket::BuiltInWebSocket::*)(), litecore::websocket::BuiltInWebSocket*>>&, std::__ndk1::__tuple_indices<>)
    ../../../../../home/couchbase/jenkins/tools/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/thread:283 void* std::__ndk1::__thread_proxy<std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct> >, std::__ndk1::__bind<void (litecore::websocket::BuiltInWebSocket::*)(), litecore::websocket::BuiltInWebSocket*> > >(void*)
    /apex/com.android.runtime/lib64/bionic/libc.so:981784 0x7f1853eb18
    /apex/com.android.runtime/lib64/bionic/libc.so:574304 0x7f184db360

What could be the cause of this crash?

Hi @Ionut_Cosmin_Mihai ,

Thank you for taking the time to report the crash. I have a couple of questions.

  1. How easy to get the crash?
  2. How to reach to the crash? This can be helped if you could please provide more logs.

Thanks,
Jianmin

The crash is happening on the clients devices in about 0.5% of the sessions. This is why we can obtain only warning and error logs(more logs from all the clients would be too much for the tool we use for error reporting).
The crash is happening after the application is backgrounded.

Hi @Ionut_Cosmin_Mihai

From the look of it, you are still running the replicator while in the background. Any app that is using too many CPU cycles will be closed by the OS and replication can get pretty intense if it’s running through a lot of documents. Also if these are tied to change events that are linked to UI you will crash. You can use Android lifecycle events to stop the replicator when you go to the background and then start it again when it comes to the foreground:

Thanks
Aaron