diff --git a/server/index.js b/server/index.js index 89dc38ed23..48ba63f62e 100644 --- a/server/index.js +++ b/server/index.js @@ -31,13 +31,25 @@ const closeSQLite = async () => { } }; +// Close properly all DuckDB connections & database const closeDuckDB = async () => { try { - await db.duckDb.close(); - logger.info('DuckDB closed.'); + return new Promise((resolve) => { + db.duckDbReadConnection.close((err1) => { + db.duckDbWriteConnection.close((err2) => { + db.duckDb.close((err3) => { + if (err1 || err2 || err3) { + logger.error(err1, err2, err3); + } + logger.info('DuckDB closed.'); + resolve(); + }); + }); + }); + }); } catch (e) { - logger.info('DuckDB database is probably already closed'); logger.warn(e); + return null; } }; diff --git a/server/models/index.js b/server/models/index.js index 904c4a2aef..d1261e09e9 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -142,6 +142,8 @@ const db = { sequelize, umzug, duckDb, + duckDbWriteConnection, + duckDbReadConnection, duckDbWriteConnectionAllAsync, duckDbReadConnectionAllAsync, duckDbCreateTableIfNotExist,