Uncaught exception: fleece::FleeceException: internal Fleece library error: Incompatible duplicate Scope

E/CouchbaseLite/DATABASE: COUCHBASE LITE CORE FATAL ERROR (backtrace follows)
********************
Uncaught exception:
fleece::FleeceException: internal Fleece library error: Incompatible duplicate Scope 0x7530275c98 for (0x74cb48425a … 0x74cb48425c) with sk=0xb400007733ba6220: conflicts with 0x7530749c98 for (0x74cb48425a … 0x74cb48425c) with sk=0xb400007733bff8d0
Backtrace:
5 libLiteCoreJNI.so litecore::jni::throwError(_JNIEnv*, C4Error) + 0
6 libLiteCoreJNI.so fleece::impl::Scope::registr() + 484
7 libLiteCoreJNI.so litecore::SQLiteQueryRunner::encodeColumn(fleece::impl::Encoder&, int) + 280
8 libLiteCoreJNI.so litecore::SQLiteQueryRunner::fastForward() + 304
9 libLiteCoreJNI.so litecore::SQLiteQuery::createEnumerator(litecore::Query::Options const*) + 172
10 libLiteCoreJNI.so litecore::SQLiteQueryEnumerator::refresh(litecore::Query*) + 160
11 0x74cb181150
12 libLiteCoreJNI.so C4QueryEnumerator* c4Internal::tryCatch<C4QueryEnumerator*>(C4Error*, fleece::function_ref<C4QueryEnumerator* ()>) + 24
13 libLiteCoreJNI.so c4queryenum_refresh + 68
14 libLiteCoreJNI.so Java_com_couchbase_lite_internal_core_C4QueryEnumerator_refresh + 60
15 0x75416d7648
16 0x75416cdfec
17 libart.so art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*) + 324
18 libart.so bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 824
19 libart.so MterpInvokeStatic + 3816
20 0x75416c8598
21 0x754167d74c
22 libart.so art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 152
23 libart.so bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art:
E/libc++abi: terminating with uncaught exception of type fleece::FleeceException: internal Fleece library error: Incompatible duplicate Scope 0x7530275c98 for (0x74cb48425a … 0x74cb48425c) with sk=0xb400007733ba6220: conflicts with 0x7530749c98 for (0x74cb48425a … 0x74cb48425c) with sk=0xb400007733bff8d0

--------- beginning of crash

A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 15356 (CBL Worker #52), pid 14308 (.sdkdemo)

Can you tell us a bit more about when and where this is happening? What version of Couchbase are you using? This looks like Android: please confirm?

@blake.meike Yes you are right about android.

Couchbase version
implementation “com.couchbase.lite:couchbase-lite-android:2.8.6”

Case: This happened when I am trying to test network usecase by switch from WiFi to network Data and vice versa. Couchbase sdk try to establish connection and than crash happened.

This is a very low-level crash involving some memory management down inside the query code, while refreshing a query listener.

TMI: there are duplicate Scopes registered for one of the const global Fleece values, probably the empty Dict. I remember we fixed this – looking up the fix in the code (Doc.cc:110) I see this was issue CBSE-10529, fixed on Aug 23.

The fix is in 3.0. I don’t think we’ve issued any patches since 2.8.6 (but I might well be wrong.)

Also worth noting: This bug is triggered as a race condition between threads. Most likely two threads running queries at the same time (on two different Database instances.)