From 58ca8f4ed8f6b381b077075c9c4ef507f93278bb Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 6 Nov 2025 14:11:38 +1100 Subject: [PATCH] fix: race condition preventing app to fully close on linux --- ts/data/dataInit.ts | 6 +++++- ts/node/sqlInstance.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ts/data/dataInit.ts b/ts/data/dataInit.ts index 319c08ed7a..541aa43c3d 100644 --- a/ts/data/dataInit.ts +++ b/ts/data/dataInit.ts @@ -263,9 +263,13 @@ function removeJob(id: number) { } function makeJob(fnName: string) { - if (_shuttingDown && fnName !== 'close') { + if (_shuttingDown && fnName !== 'close' && fnName !== 'removeDB') { throw new Error(`Rejecting SQL channel job (${fnName}); application is shutting down`); } + if (!_shuttingDown && fnName === 'close') { + window?.log?.debug(`SQL channel job close() called, marking as shutting down`); + _shuttingDown = true; + } _jobCounter += 1; const id = _jobCounter; diff --git a/ts/node/sqlInstance.ts b/ts/node/sqlInstance.ts index 5491c937d3..850fc25776 100644 --- a/ts/node/sqlInstance.ts +++ b/ts/node/sqlInstance.ts @@ -37,7 +37,7 @@ export function closeDbInstance() { } const dbRef = globalInstance; globalInstance = null; - // SQLLite documentation suggests that we run `PRAGMA optimize` right before + // SQlite documentation suggests that we run `PRAGMA optimize` right before // closing the database connection. dbRef.pragma('optimize'); dbRef.close();