You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just tested my app with two tabs open, and on the second tab, DB access is always somehow locked. When I don't use exclusive locking, my app works as expected. Is it possible I am doing something wrong?
I think the behavior you describe is working as expected. That's how exclusive locking works; it takes a lock and holds on to it:
When the locking-mode is set to EXCLUSIVE, the database connection never releases file-locks. The first time the database is read in EXCLUSIVE mode, a shared lock is obtained and held. The first time the database is written, an exclusive lock is obtained and held.
Note that while this says that when the database is read a shared lock is held, the stock IDBBatchAtomicVFS doesn't use shared locking, i.e. only one connection can hold the lock at a time even if only reading.
If you want to release the exclusive mode lock so another context can access the database, you have to either close the connection or change the mode and access the database:
Database locks obtained by a connection in EXCLUSIVE mode may be released either by closing the database connection, or by setting the locking-mode back to NORMAL using this pragma and then accessing the database file (for read or write). Simply setting the locking-mode to NORMAL is not enough - locks are not released until the next time the database file is accessed.
Thank you for your answer. If I understand it correctly, it means I have to implement some mechanism over wa-sqlite, if I want to use it with more than one tab. I have almost no idea, how that mechanism should work. Should I observe tab focus/blur? A simple example would be great.
Meanwhile, if I will not use EXCLUSIVE mode, do I have to use WebLock? Probably yes. Then I don't understand the point of the whole async API, because, with custom WebLock, the sync version should be OK. Am I correct? Thank you for your work.
Repository owner
locked and limited conversation to collaborators
Jun 14, 2022
I just tested my app with two tabs open, and on the second tab, DB access is always somehow locked. When I don't use exclusive locking, my app works as expected. Is it possible I am doing something wrong?
The text was updated successfully, but these errors were encountered: