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

Is it possible to wait until the database is unlocked? #331

Closed
iddm opened this issue Feb 16, 2018 · 10 comments
Closed

Is it possible to wait until the database is unlocked? #331

iddm opened this issue Feb 16, 2018 · 10 comments

Comments

@iddm
Copy link

iddm commented Feb 16, 2018

I tried to use r2d2 + diesel + sqlite crates for working with my sqlite database from multiple threads. However, it seems to be useless to use connection pool since everytime the database is locked the error is returned immediately without even waiting until it is unlocked by another thread. Is there a wait to specify some timeout for a connection and make it wait until one is free?

@gwenn
Copy link
Collaborator

gwenn commented Feb 20, 2018

In the same process, yes you can.
See sqlite3_unlock_notify.
But you will need to patch rusqlite.

@iddm
Copy link
Author

iddm commented Feb 21, 2018

Thanks, cool. Why nobody merges it? And why I think it should be enabled always if it is used from r2d2.

@gwenn
Copy link
Collaborator

gwenn commented Feb 21, 2018

@iddm
Copy link
Author

iddm commented Feb 21, 2018

Thanks

@ajensen123
Copy link

Can gwenn please provide a code example for how to use the "unlock-notify" branch. I need to write a re-entrant query function that checks the locked status of the database beforehand and then waits a random time period before retrying.

@ajensen123
Copy link

Having looked at this branch's code a little more closely, it appears that simply enabling the "unlock_notify" feature means that the internal "prepare" statement will wait until the database is unlocked before exiting. Is there any chance that it could end up waiting forever or an excessively long time?

I compiled the application with the following cargo.toml dependency defined. Is this all I have to do to enable this feature? (I'm a Rust Newbie).

rusqlite = { git = "https://github.com/gwenn/rusqlite", branch = "unlock-notify", features = ["bundled","chrono","unlock_notify"]}

@gwenn
Copy link
Collaborator

gwenn commented May 3, 2018

Currently, there is no timeout but you just have to replace the wait by a wait_timeout

@tcr
Copy link

tcr commented Jun 13, 2018

@gwenn Can this be closed as of https://github.com/jgallagher/rusqlite/pull/349 ?

@gwenn
Copy link
Collaborator

gwenn commented Jun 13, 2018

Indeed, in next release.

@gwenn
Copy link
Collaborator

gwenn commented Aug 17, 2018

rusqlite 0.14 released

@gwenn gwenn closed this as completed Aug 17, 2018
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

No branches or pull requests

4 participants