[Fix] OPFS Potential Deadlocks #56
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Related to:
The following issue is quite difficult to reproduce. I cannot reproduce it in this WA-SQLite demo. It can be reproduced in our PowerSync JS SDK.
When opening multiple tabs (approximately 5 or more) and rapidly cycling through the tabs and refreshing. Two possible issues can occur.
A stuck navigator lock
When the SQLite database is opened, the
#requestAccessHandleis called. This method requests a navigator lock which resolves to a releaser function. It then attempts to asynchronously create a synchronous access handle for the 3 sqlite persistent files. If, for any reason, the creation of the synchronous access handles failed, the lock does not seem to be released. Theopencall is retried, but is stuck on the request to obtain the lock (possibly since it's already obtained).An example of when the open is stuck waiting for a lock

I'm not exactly sure what could cause these calls to fail. Perhaps there is some browser behaviour which could cause these calls to fail.
If we
try...catchthis process and release the lock on error, then we no longer experience these deadlocks in our testing.NoModificationAllowed Errors
In the above refreshing test, we often also see the follow error (which is easier to reproduce in Firefox)
Again, not entirely sure why this is happening. The main theory at this point is that, for some reason, creating 1 of the 3 persistent access handles fail - but 1 or more of them might have succeeded. One the next retry we might be attempting to open an access handle which is already open.