fix(duckdb): explicitly close connections to release file locks on Windows

DuckDB opens database files with exclusive locks on Windows. Previously
connections were only released via Drop, which may not release the file
handle synchronously, causing "file already in use" errors when
reconnecting or testing connections in quick succession.
This commit is contained in:
t8y2 committed 2026-05-27 13:53:14 +08:00
1 parent bcfad319a6
commit a296bd6c3c
3 files changed
+33 -4

No files matched your search

+6 -3
View File
@@ -269,8 +269,9 @@ pub async fn test_connection(state: State<'_, Arc<AppState>>, config: Connection
if state.duckdb_existing_pool_is_usable_for_config(&config).await? {
Ok("Connection successful".to_string())
} else {
db::duckdb_driver::connect_path(&expand_tilde(&config.host))
.map(|_| "Connection successful".to_string())
let con = db::duckdb_driver::connect_path(&expand_tilde(&config.host))?;
dbx_core::db::duckdb_driver::close_connection(con);
Ok("Connection successful".to_string())
}
}
DatabaseType::MongoDb => {
@@ -474,7 +475,9 @@ pub async fn disconnect_db(state: State<'_, Arc<AppState>>, connection_id: Strin
PoolKind::Postgres(p) => p.close(),
PoolKind::Sqlite(_) => {}
PoolKind::Redis(_) => {}
PoolKind::DuckDb(_) => {}
PoolKind::DuckDb(con) => {
dbx_core::db::duckdb_driver::close_connection(con);
}
PoolKind::MongoDb(_) => {}
PoolKind::ClickHouse(_) => {}
PoolKind::SqlServer(_) => {}