-
Notifications
You must be signed in to change notification settings - Fork 38
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
Starting replicator while transaction is open causes deadlock #476
Comments
Created CBL-4548 |
@blaugold May I ask what is the concrete situation you came to encounter? Your statement is correct; I just wonder whether you wanted to point it out or you have come across this situation in a tricky way. |
@jianminzhao I came across this issue in the context of the async API of the Couchbase Lite SDK for Dart/Flutter, that I'm maintaining. The SDK has a fully synchronous API and another corresponding API with the same functionality but async return values. The async API offloads all work to another thread to prevent blocking the main thread. In async code, it is easy for code to interleave in unexpected ways during execution. The callback of the async I have already implemented a mitigation in the Dart SDK, which is to asynchronously wait for any pending transaction before starting a replicator. For the sync API, an error is thrown if the user tries to start a replicator from within the I mostly raised this issue to make the team aware of this limitation. Just documenting it should be fine, IMHO. |
@blaugold thanks for your explanation. I think this, "which is to asynchronously wait for any pending transaction before starting a replicator," is a good approach. Being a transaction, it is meant to be a sequestered context. By the way, have you tried to start the replicator asynchronously in a separate thread? |
I was under the impression that it is not officially supported to access a database and related resources from multiple threads. That is why I architected the async API to create one thread per database and schedule all work on that thread. So, no, but now I'm seeing that some operations have the note "This function is thread-safe." :)
I think that extra info would have helped! |
Ah, that's in LiteCore. I don't think the documentation for the C SDK says anything about a function being thread-safe, no? |
The only note about thread safety of the C SDK I could find is this:
It would probably be good to make this clear early on in Couchbase Lite docs, not just in this one sentence of the reference. 😉 |
"Thread safe" means we will not access the database you passed to the the replicator and race with your accesses. To do it, we open a new database connection through that all database accesses are done. This is the very reason you got deadlocked when start the replicator in your transaction. |
Calling
CBLReplicator_Start
while the target database has an open transaction causes a deadlock.The text was updated successfully, but these errors were encountered: