Database is Busy/locked

CouchbaseLiteException (LiteCoreDomain / 16): database is locked.

In Windows Forms Application, we are using Couchbase.Lite community edition v2.7.1 .NET SDK
The above error is occurring in PushAndPull Replicator. Please help me to solve this issue?
How to unlock database ?

1 Like

@venkatreddy, Are you trying to access the database or deleting the database? this happens when you try to delete the database and when replication is still continuing

@sridevi.saragadam No, Am not deleting database. just accessing database. Some documents will update continuously and PushAndPull replicator is always in running

Hi @venkatreddy,
Can you provide more info? Code snippet to repro the issue and logs to show the issue you are describing?
thanks!

@Sandy_Chuang Actually, the problem rising randomly. we can not reproduce it.
why this database locked issue will arise?

And what logs do you need ? couchbase logs ?

Hi @venkatreddy
Yes CBL logs. Along with logs, please also provide us the description/steps that cause the issue happened would be helpful.
So far we know you are not deleting the db while replication is still going. What about other actions, say close the db while replication is still going? or?

We are experiencing the same issue. Every time the replicator becomes busy in (PushAndPull and Continuous = true mode), the database becomes locked “CouchbaseLiteException (LiteCoreDomain / 16): database is locked.” and user reads/writes are impossible. It seems to be a limitation of SQLLite level of concurrency. If a process has an exclusive lock on the database and another connection will time out waiting for the lock to be released. Is there a workaround for this limitation?

In SQLite’s WAL mode, which we use, reads are always possible while another connection is writing to the database.

Concurrent writes are blocked, but only for as long as the other connection is in a write transaction, which should be a very short time. The thread attempting to write will retry for several seconds (I don’t remember the exact number) before giving up.

How long is the affected thread blocking before it throws the exception?

It’s best if you file a bug report against couchbase-lite-core. Please include logs, and identify what version/platform of CBL, and what OS.

(Unless you’re a Couchbase customer, in which case you should file a support request.)

We have Win 7 & 10 desktop offline-first application. This doesn’t happen often for us. In one example there it does happen if a user doesn’t use the application for several days, and once they open it up the replication kicks in and it has to catch up with all the changes. At one point a user had to wait for an hour so we just told him to close and re-open the app (at which point the replicator restarted) and things were back to normal… Would running the replicator as a Windows service, so that it always replicates regardless if the app is open or not, be a good solution, are there any pitfalls with that setup?

How many changes did it have to catch up with? The replicator can download 1,000 or more docs per second, depending on network bandwidth, server load, etc.

At one point a user had to wait for an hour so we just told him to close and re-open the app

Are you saying the replicator got stuck? In that case it’s possible one of its threads deadlocked while it had a db transaction open, which would cause the lock exceptions you described. In that case it would be really important to get a thread dump.

It was probably around 1,000. The network is fast its LAN, user’s hardware is a bit on the slow side i3, HDD. It feels like it got stuck, but I’m not sure how to confirm that. How would I get the thread dump from users machine?

Sorry, I know almost nothing about Windows. Maybe @borrrden or @Sandy_Chuang have advice.

You can create a dump file from the task manager as explained by the wonderful people over at Mozilla!