Skip to content

Use busy_timeout for better lock handling across Isolates #34

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

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Apr 2, 2024

While read statements can execute concurrently on multiple connections, write statements and transactions use an exclusive lock. Currently, a global database-level lock is maintained and exposed across isolates, but this requires explicitly passing an IsolateConnectionFactory across Isolates. This is fine when explicitly spawning a new Isolate to do background work from the main Isolate, but does not work when the Isolates are managed externally, for example when using flutter_workmanager.

This configures SQLite busy_timeout to 30 seconds to work around the issue. When another connection is locking the database, SQLite will retry until the timeout has been reached.

In principle that makes our own global mutex redundant, and removing it can give some performance gains. That will form a separate PR - see #35.

@rkistner rkistner mentioned this pull request Apr 2, 2024
@rkistner rkistner marked this pull request as ready for review April 3, 2024 11:57
@rkistner rkistner mentioned this pull request Apr 3, 2024
@rkistner rkistner merged commit 662e578 into main Apr 4, 2024
6 checks passed
@rkistner rkistner deleted the multi-isolates branch April 4, 2024 13:04
@rkistner rkistner mentioned this pull request Apr 4, 2024
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

Successfully merging this pull request may close these issues.

2 participants