diff --git a/core/lib.rs b/core/lib.rs index a32e5497b5..b5ba3128f9 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -1190,11 +1190,8 @@ unsafe impl Sync for Connection {} impl Drop for Connection { fn drop(&mut self) { - if !self.is_closed() { - // if connection wasn't properly closed, decrement the connection counter - self.db - .n_connections - .fetch_sub(1, std::sync::atomic::Ordering::SeqCst); + if let Err(e) = self.close() { + tracing::error!("Error closing connection: {}", e); } } } diff --git a/tests/integration/query_processing/test_write_path.rs b/tests/integration/query_processing/test_write_path.rs index e3bddb095a..9920e8d432 100644 --- a/tests/integration/query_processing/test_write_path.rs +++ b/tests/integration/query_processing/test_write_path.rs @@ -781,6 +781,9 @@ fn test_wal_bad_frame() -> anyhow::Result<()> { conn.execute("INSERT INTO t2(x) VALUES (1)")?; conn.execute("INSERT INTO t3(x) VALUES (1)")?; conn.execute("COMMIT")?; + // disalbe auto checkpoint so we keep the state of the WAL file on disk and prevent + // truncate checkpoint automatically on connection drop + conn.wal_auto_checkpoint_disable(); common::run_query_on_row(&tmp_db, &conn, "SELECT count(1) from t2", |row| { let x = row.get::(0).unwrap(); assert_eq!(x, 1); @@ -791,6 +794,7 @@ fn test_wal_bad_frame() -> anyhow::Result<()> { assert_eq!(x, 1); }) .unwrap(); + // Now let's modify last frame record let path = tmp_db.path.clone(); let path = path.with_extension("db-wal"); diff --git a/tests/integration/storage/checksum.rs b/tests/integration/storage/checksum.rs index 8fb3e42c52..5deaf667cc 100644 --- a/tests/integration/storage/checksum.rs +++ b/tests/integration/storage/checksum.rs @@ -34,7 +34,7 @@ fn test_per_page_checksum() -> anyhow::Result<()> { { let metadata = std::fs::metadata(&db_path)?; - assert_eq!(metadata.len(), 4096, "db file should be exactly 4096 bytes"); + assert_eq!(metadata.len(), 8192, "db file should be exactly 8kb"); } // let's test that page actually contains checksum bytes @@ -42,13 +42,13 @@ fn test_per_page_checksum() -> anyhow::Result<()> { let file_contents = std::fs::read(&db_path)?; assert_eq!( file_contents.len(), - 4096, + 8192, "file contents should be 4096 bytes" ); // split the page: first 4088 bytes are actual page, last 8 bytes are checksum let actual_page = &file_contents[..4096 - 8]; - let checksum_bytes = &file_contents[4096 - 8..]; + let checksum_bytes = &file_contents[4096 - 8..4096]; let stored_checksum = u64::from_le_bytes(checksum_bytes.try_into().unwrap()); let expected_checksum = twox_hash::XxHash3_64::oneshot(actual_page);