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

Handle locked database #163

Closed
squaregoldfish opened this issue Jan 26, 2019 · 5 comments
Closed

Handle locked database #163

squaregoldfish opened this issue Jan 26, 2019 · 5 comments

Comments

@squaregoldfish
Copy link
Contributor

If one process is writing to a database, nothing else can read from it because it's locked. This results in an SQLite.SQLiteException("database is locked"). We can get round this by catching the exception and trying again after a few milliseconds, but would it be desirable to build this functionality into the library?

There's a number of ways it could be done, but the most obvious is to add optional arguments for handleLockedDatabase=true|false and a timeout=x, which is a number of seconds to keep retrying before giving up. I guess handleLockedDatabases should be false by default. Although it would be useful to be able to set a global option somehow to save setting it every time.

I'm willing to do some work on this if you think it's a good idea.

@quinnj
Copy link
Member

quinnj commented Jan 27, 2019

We could potentially provide a macro retry that implemented the logic you've mentioned. I kind of like the idea of having a macro that people would then use like @retry SQLite.query(db, "...") because it's pretty lightweight and doesn't mess with global settings/config or anything. With global settings, I always worry because of situations where a package you're using ends up using SQLite for something and they're setting their own global settings and now they're messing with yours, etc. A quick macro seems like a way users can easily get the functionality w/o affecting others.

Does that sound ok? I'm happy to help discuss what the implementation would look like if necessary (depending on your comfort level with macros).

@squaregoldfish
Copy link
Contributor Author

A macro sounds like a perfect solution! I've never written a proper one before, but I'll do some reading and see if I can make something.

@tosone
Copy link

tosone commented Mar 28, 2020

we should set this busy_timeout definition, @retry is not a good solution.

https://www.sqlite.org/pragma.html#pragma_busy_timeout

@hellemo
Copy link
Contributor

hellemo commented Sep 20, 2020

Please have a look at #218 adding support for busy_timeout

@quinnj
Copy link
Member

quinnj commented Oct 7, 2020

I don't quite understand how busy_timeout works, but for those that do, I'd gladly welcome any additional PRs that could provide nice a nice API for handling a locked database.

@quinnj quinnj closed this as completed Oct 20, 2021
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