Crashes in Couchbase lite 3.1.0

Hi

I have come across the following crashes on couchbase lite 3.1.0 in android in my firebase crashlytics logs.
I was wondering if you have advise on what could be causing them or if you are aware of them and there is a fix.

Fatal Exception: java.lang.IllegalStateException: Unbalanced enter/exit
       at okio.AsyncTimeout$Companion.scheduleTimeout(AsyncTimeout.kt:225)
       at okio.AsyncTimeout$Companion.access$scheduleTimeout(AsyncTimeout.kt:201)
       at okio.AsyncTimeout.enter(AsyncTimeout.kt:54)
       at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:331)
       at okio.RealBufferedSource.indexOf(RealBufferedSource.kt:427)
       at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:320)
       at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
       at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:178)
       at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106)
       at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at com.couchbase.lite.internal.replicator.AbstractCBLWebSocket.lambda$setupBasicAuthenticator$1(AbstractCBLWebSocket.java:653)
       at com.couchbase.lite.internal.replicator.AbstractCBLWebSocket$$ExternalSyntheticLambda2.intercept(:2)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)
Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "libLiteCoreJNI.so" not found
       at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
       at java.lang.Runtime.loadLibrary0(Runtime.java:998)
       at java.lang.System.loadLibrary(System.java:1661)
       at com.couchbase.lite.internal.CouchbaseLiteInternal.init(CouchbaseLiteInternal.java:93)
       at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:62)
       at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:46)

Thanks for bringing this to my attention.
This is a bug. I don’t know what is wrong yet. I’ve filed CBL-4643 to track it and will schedule it for immediate attention.

ADDED:
A quick google suggests that this may be an OkHttp bug.

@meirrosendorff : Android logging can include the id of the thread on which the exception occurred. If you can get that for me, it would be invaluable. … Also helpful (though I know it is hard to do) would be a bit of the system (logcat) log at the time the issue occurs.

Although I am pretty sure this is bug – and one that was introduced relatively recently – it is quite difficult to reproduce. Any logs you can get for me would be a huge help.

ADDED:
I have an experimental version of CBL Android and would be very interested in having you try it out, to see if we can learn anything.

Also, it would be quite useful to know the type of phone and the version of Android on which these failures are occurring.

Hi @blake.meike
Apologies for the delayed response

This is all the information on the thread pool at the time of the crash, not sure if you can discern which thread it occurred on.

issue_ed0ab7f90882f9a103366424a93d6e12_crash_session_64941A25028000011F885073C97D9660_DNE_0_v2_stacktrace.txt.zip (3.8 KB)

Additionally here is all device details on the device with the most recent crash.

Unfortunately I have not been able to replicate this locally, if I manage to produce any logs of it happening I will send it through to you immediately.

I am happy to try an experimental version, how experimental is it as can’t deploy something too unstable to these clients ?

Great stuff @meirrosendorff! Thank you. This might be a different issue, though. It looks like an NPE, not the exception from the OP.

FWIW, my current suspicion is that the problem is here: AssertionError at AsyncTimeout.java:101 for some android 4.4.2 and 4.4.4 devices · Issue #3641 · square/okhttp · GitHub

At the moment, it appears likely that any changes I make to address the issue will be part of an official (not experimental) patch release of the 3.1 line.

Will keep you posted.

-blake

@meirrosendorff : I am seeing some evidence that we are not using the same version of OkHttp. I am buildng and testing against OkHttp 3.14.7. Is it possible that your code depends on a different version?

Howzit @blake.meike

I am so sorry I missed this message, I checked my dependencies and it seems my application uses okhttp 4.9.3.

The next version of Couchbase Lite (>3.1.x) will use at least okhhtp 4.11.0. I will be testing pretty extensively with that. The 3.1 line expects 3.14.7 and has never been tested with anything else.

That said, Couchbase Lite 3.1.1 (probably out sometime this month) does attempt to address this issue: when it occurs, it should be logged as an error but should not cause your application to crash.

Please let me know if that helps.

1 Like