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

SQLite backend does not close db connection correctly #2249

Open
rsk700 opened this issue Dec 21, 2022 · 0 comments
Open

SQLite backend does not close db connection correctly #2249

rsk700 opened this issue Dec 21, 2022 · 0 comments
Labels

Comments

@rsk700
Copy link

rsk700 commented Dec 21, 2022

Bug Description

As in code example below I open db in WAL mode, and after closing pool, "-wal" and "-shm" files not deleted (which sqlite deletes when last connection closes). I've looked at source code and only place calling sqlite3_close is:
https://github.com/launchbadge/sqlx/blob/v0.6.2/sqlx-core/src/sqlite/connection/handle.rs#L99

but it looks like it never called (I've made simple test by putting panic! in start of ConnectionHandle::drop)

related issue: #272

Minimal Reproduction

Cargo.toml:

[package]
name = "sqlitewal"
version = "0.1.0"
edition = "2021"

[dependencies]
sqlx = { version="0.6.2", features=["runtime-tokio-rustls", "sqlite"] }
tokio = { version="1", features=["macros"] }
anyhow = "1.0"

main.rs:

use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePool};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let options = SqliteConnectOptions::new()
        .filename("d1.sqlite")
        .create_if_missing(true)
        .journal_mode(SqliteJournalMode::Wal);
    let pool = SqlitePool::connect_with(options).await?;
    sqlx::query("create table if not exists t1 (a text);")
        .execute(&pool)
        .await?;
    sqlx::query("insert into t1 (a) values (?)")
        .bind("aaa")
        .execute(&pool)
        .await?;
    pool.close().await;

    Ok(())
}

Info

  • SQLx version: 0.6.2
  • SQLx features enabled: "runtime-tokio-rustls", "sqlite"
  • Database server and version: SQLite 3.31.1
  • Operating system: Ubuntu 20.04.5 LTS
  • rustc --version: rustc 1.66.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant