Skip to content

Commit ba3994e

Browse files
committed
chore(sqlite): add repro for #1419
1 parent 593364f commit ba3994e

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

Cargo.lock

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/sqlite/sqlite.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,54 @@ async fn concurrent_resets_dont_segfault() {
567567

568568
sqlx_rt::sleep(Duration::from_millis(1)).await;
569569
}
570+
571+
// https://github.com/launchbadge/sqlx/issues/1419
572+
// note: this passes before and after the fix; you need to run it with `--nocapture`
573+
// to see the panic from the worker thread, which doesn't happen after the fix
574+
#[sqlx_macros::test]
575+
async fn row_dropped_after_connection_doesnt_panic() {
576+
for _ in 0..2 {
577+
let mut conn = SqliteConnection::connect(":memory:").await.unwrap();
578+
579+
conn.execute(
580+
"CREATE TABLE IF NOT EXISTS books
581+
(
582+
title TEXT NOT NULL,
583+
created_at INTEGER DEFAULT (cast(strftime('%s','now') as int)),
584+
updated_at INTEGER DEFAULT (cast(strftime('%s','now') as int))
585+
);
586+
587+
INSERT INTO books(title) VALUES('hello');
588+
INSERT INTO books(title) VALUES('test');
589+
INSERT INTO books(title) VALUES('example');
590+
INSERT INTO books(title) VALUES('stuff');
591+
INSERT INTO books(title) VALUES('here');
592+
INSERT INTO books(title) VALUES('there');
593+
INSERT INTO books(title) VALUES('everywhere');",
594+
)
595+
.await
596+
.unwrap();
597+
598+
let books = sqlx::query("SELECT * FROM books")
599+
.fetch_all(&mut conn)
600+
.await
601+
.unwrap();
602+
603+
for book in &books {
604+
// force the row to be inflated
605+
let title: String = book.get("title");
606+
607+
sqlx::query("DELETE FROM books WHERE title = ?")
608+
.bind(&title)
609+
.execute(&mut conn)
610+
.await
611+
.unwrap();
612+
}
613+
614+
// hold `_books` past the lifetime of `conn`
615+
drop(conn);
616+
drop(books);
617+
618+
sqlx_rt::sleep(std::time::Duration::from_millis(50)).await
619+
}
620+
}

0 commit comments

Comments
 (0)