From 61167f664644a60d207e7d2d8a0c3bedd2543397 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 14 Apr 2020 22:15:55 +0200 Subject: [PATCH] make sure to close sqlite connection on exit --- src/services/sql.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/services/sql.js b/src/services/sql.js index dba837c51..a928f319e 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -9,6 +9,16 @@ function setDbConnection(connection) { dbConnection = connection; } +[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach(eventType => { + process.on(eventType, () => { + if (dbConnection) { + // closing connection is especially important to fold -wal file into the main DB file + // (see https://sqlite.org/tempfiles.html for details) + dbConnection.close(); + } + }); +}); + async function insert(tableName, rec, replace = false) { const keys = Object.keys(rec); if (keys.length === 0) {