From ba3994e53007a0839be4ed612f0359488a92bb01 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Wed, 22 Sep 2021 15:48:49 -0700 Subject: [PATCH] chore(sqlite): add repro for #1419 --- Cargo.lock | 15 +++++-------- tests/sqlite/sqlite.rs | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69fe3ba159..640d9b97ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1029,12 +1029,6 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - [[package]] name = "hashbrown" version = "0.11.2" @@ -1050,7 +1044,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" dependencies = [ - "hashbrown 0.11.2", + "hashbrown", ] [[package]] @@ -1115,12 +1109,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg 1.0.1", - "hashbrown 0.9.1", + "hashbrown", ] [[package]] @@ -2424,6 +2418,7 @@ dependencies = [ "hashlink", "hex", "hmac", + "indexmap", "ipnetwork", "itoa", "libc", diff --git a/tests/sqlite/sqlite.rs b/tests/sqlite/sqlite.rs index e794f49a74..d7cd55cb1b 100644 --- a/tests/sqlite/sqlite.rs +++ b/tests/sqlite/sqlite.rs @@ -567,3 +567,54 @@ async fn concurrent_resets_dont_segfault() { sqlx_rt::sleep(Duration::from_millis(1)).await; } + +// https://github.com/launchbadge/sqlx/issues/1419 +// note: this passes before and after the fix; you need to run it with `--nocapture` +// to see the panic from the worker thread, which doesn't happen after the fix +#[sqlx_macros::test] +async fn row_dropped_after_connection_doesnt_panic() { + for _ in 0..2 { + let mut conn = SqliteConnection::connect(":memory:").await.unwrap(); + + conn.execute( + "CREATE TABLE IF NOT EXISTS books +( + title TEXT NOT NULL, + created_at INTEGER DEFAULT (cast(strftime('%s','now') as int)), + updated_at INTEGER DEFAULT (cast(strftime('%s','now') as int)) +); + +INSERT INTO books(title) VALUES('hello'); +INSERT INTO books(title) VALUES('test'); +INSERT INTO books(title) VALUES('example'); +INSERT INTO books(title) VALUES('stuff'); +INSERT INTO books(title) VALUES('here'); +INSERT INTO books(title) VALUES('there'); +INSERT INTO books(title) VALUES('everywhere');", + ) + .await + .unwrap(); + + let books = sqlx::query("SELECT * FROM books") + .fetch_all(&mut conn) + .await + .unwrap(); + + for book in &books { + // force the row to be inflated + let title: String = book.get("title"); + + sqlx::query("DELETE FROM books WHERE title = ?") + .bind(&title) + .execute(&mut conn) + .await + .unwrap(); + } + + // hold `_books` past the lifetime of `conn` + drop(conn); + drop(books); + + sqlx_rt::sleep(std::time::Duration::from_millis(50)).await + } +}