Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBLQuery_AddChangeListener deadlocks when called in transaction after CBLDatabase_BeginTransaction #497

Open
jeffdgr8 opened this issue Jul 6, 2023 · 3 comments

Comments

@jeffdgr8
Copy link

jeffdgr8 commented Jul 6, 2023

I’ve run into a bug with an extension on my Kotlin Multiplatform Couchbase Lite library where I add a query change listener within a transaction. This code works on Android and JVM using the Java SDK and iOS and macOS using the Objective-C SDK, but not on Linux and Windows using the native C SDK. The C SDK deadlocks and hangs when calling CBLQuery_AddChangeListener after calling CBLDatabase_BeginTransaction. This is with Couchbase Lite version 3.0.12.

Original forum post.

@blaugold
Copy link
Contributor

It might be related to CBL-4548 (#476).

@jianminzhao
Copy link
Contributor

In general, we should avoid configuring the database inside an open transaction. In this case, to add a change listener, we will wire into the database to receive changes. While doing the wiring, we may require a new transaction and trapped in deadlock. Is there a specific reason you want to add the listener while inside your transaction?

@jeffdgr8
Copy link
Author

@blaugold yes, this looks like a similar limitation. As Blake notes, there are a lot of things that aren't allowed to be done within an open transaction. A helpful error message would be a better UX rather than hanging the application in deadlock though, which is harder to debug.

@jianminzhao I describe my use case a bit more in my forum post. Essentially my ideal goal would to get the initial live query results from within the transaction that also performed the count query to calculate the offset for the live query. This way there's a guarantee that the database query results haven't been updated since the count query was executed, and if they have, the live query observer would then call the observer again with the updated result set. Since the live query observer is asynchronous, this complicates this goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants