Skip to content
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

Fix "database is locked" errors in multi-threaded programs #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niner
Copy link

@niner niner commented Nov 19, 2021

If not specified explicitly, a begin will start a deferred transaction, i.e.
one that will not attain any locks right away. Instead a read lock is taken
when the first select statement is run and this will be upgraded to a write
lock on the first insert/update/delete statement. If a concurrent transaction
already holds a write lock though, upgrading (or attaining it initially) may
fail with SQLITE_BUSY which gets reported as "database is locked".

According to
https://stackoverflow.com/questions/6369677/database-is-locked-error-in-sqlite3-with-qt
this can be worked around by explicilty starting an immediate transaction.
This will attain a write lock immediately. It can still fail with SQLITE_BUSY,
but before failing it will wait and try again automatically. This has much
better chances of succeeding than the retry on upgrading a lock, because there are no
previous results that could be invalidated by that concurrent transaction.

This fixes the test fail on the upcoming Rakudo 2021.12 release.

If not specified explicitly, a `begin` will start a deferred transaction, i.e.
one that will not attain any locks right away. Instead a read lock is taken
when the first select statement is run and this will be upgraded to a write
lock on the first insert/update/delete statement. If a concurrent transaction
already holds a write lock though, upgrading (or attaining it initially) may
fail with SQLITE_BUSY which gets reported as "database is locked".

According to
https://stackoverflow.com/questions/6369677/database-is-locked-error-in-sqlite3-with-qt
this can be worked around by explicilty starting an immediate transaction.
This will attain a write lock immediately. It can still fail with SQLITE_BUSY,
but before failing it will wait and try again automatically. This has much
better chances of succeeding than the retry on upgrading a lock, because there are no
previous results that could be invalidated by that concurrent transaction.

This fixes the test fail on the upcoming Rakudo 2021.12 release.
@niner niner mentioned this pull request Nov 19, 2021
18 tasks
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.

1 participant