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

How does it handle SQLITE_BUSY error? #155

Closed
pleerock opened this issue Jul 30, 2018 · 6 comments
Closed

How does it handle SQLITE_BUSY error? #155

pleerock opened this issue Jul 30, 2018 · 6 comments

Comments

@pleerock
Copy link

How does it handle SQLITE_BUSY error? Can we handle it somehow properly to make first process to wait until another writes?

In node-sqlite3 there is an opened issue with handling sqlite busy error.

@mandaputtra
Copy link

mandaputtra commented Sep 2, 2018

If busy then you should maybe open the database with other app, and you forgot to save it.

Or maybe because sqlite not yet finish querying

@JoshuaWise
Copy link
Member

JoshuaWise commented Sep 9, 2018

When the database is busy, better-sqlite3 currently waits 5 seconds before allowing sqlite to throw a SQLITE_BUSY error. This value may be configurable in the future.

If you want to permit longer busy times, you could wrap your query in a try-catch-retry loop. However, it's more likely that you have some kind unintentional locking happening in your application (as @mandaputtra pointed out).

@JoshuaWise
Copy link
Member

Here's an example of a try-catch-retry loop.

const db = require('better-sqlite3')('my-database.db');

const stmt = db.prepare(SQL);

while (true) {
  try {
    stmt.run();
    break;
  } catch (err) {
    if (err.code !== 'SQLITE_BUSY') throw err;
  }
}

@JoshuaWise
Copy link
Member

JoshuaWise commented Oct 9, 2018

As of version 5.0.0, there's now an option to specify a custom timeout, instead of the default 5 seconds. Read about it here.

@tintin10q
Copy link

For me I get the "This database connection is busy executing a query" error way before 5 seconds.

@titanism
Copy link

titanism commented Oct 27, 2023

For me I get the "This database connection is busy executing a query" error way before 5 seconds.

same here, the timeout does not seem to be respected

edit: I'm using ava and it's using multiple processes/threads so that's probably culprit (ref: #1067)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants