@@ -567,3 +567,54 @@ async fn concurrent_resets_dont_segfault() {
567
567
568
568
sqlx_rt:: sleep ( Duration :: from_millis ( 1 ) ) . await ;
569
569
}
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