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

DatabaseBusy error on pool creation with a new file #10

Open
tomasol opened this issue Apr 14, 2024 · 2 comments
Open

DatabaseBusy error on pool creation with a new file #10

tomasol opened this issue Apr 14, 2024 · 2 comments

Comments

@tomasol
Copy link

tomasol commented Apr 14, 2024

Hi, thanks for the library. I am running into an issue during tests, where I am creating a temporary database with a pool:

let pool = PoolBuilder::new()
            .path(path)
            .journal_mode(JournalMode::Wal)
            .open()
            .await?;

Occasionally I get an error:

Rusqlite(SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked")))

The workaround is to create the file before creating the pool:

let client = ClientBuilder::new()
            .path(&path)
            .journal_mode(JournalMode::Wal)
            .open()
            .await?;
        client.close().await?;
let pool = ...

Not sure if this is worth fixing or just mentioning in docs.

@ryanfowler
Copy link
Owner

Sorry for the delayed response, but thanks for filing an issue! I'm curious, what connection parameters are you using to connect?

@tomasol
Copy link
Author

tomasol commented Jul 23, 2024

No problem. Here is a more complete example:

async_test!(check_init);

async fn check_init() {
    let file = tempfile::NamedTempFile::new().unwrap();
    let path = file.path();
    let pool = PoolBuilder::new()
        .path(path)
        .journal_mode(JournalMode::Wal)
        // .num_conns(1)
        .open()
        .await
        .unwrap();
}

Running the test in a loop fails within seconds.

while true; do cargo test --workspace check_init || break; done

Note that the file must not exist before the test. The other workaround is to set num_conns(1).

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

2 participants