Skip to content

Commit 3c6e802

Browse files
authored
Merge pull request #1674 from session-foundation/fix-race-condition-app-closing
fix: race condition preventing app to fully close on linux
2 parents aaa5bf6 + 58ca8f4 commit 3c6e802

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ts/data/dataInit.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,13 @@ function removeJob(id: number) {
263263
}
264264

265265
function makeJob(fnName: string) {
266-
if (_shuttingDown && fnName !== 'close') {
266+
if (_shuttingDown && fnName !== 'close' && fnName !== 'removeDB') {
267267
throw new Error(`Rejecting SQL channel job (${fnName}); application is shutting down`);
268268
}
269+
if (!_shuttingDown && fnName === 'close') {
270+
window?.log?.debug(`SQL channel job close() called, marking as shutting down`);
271+
_shuttingDown = true;
272+
}
269273

270274
_jobCounter += 1;
271275
const id = _jobCounter;

ts/node/sqlInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function closeDbInstance() {
3737
}
3838
const dbRef = globalInstance;
3939
globalInstance = null;
40-
// SQLLite documentation suggests that we run `PRAGMA optimize` right before
40+
// SQlite documentation suggests that we run `PRAGMA optimize` right before
4141
// closing the database connection.
4242
dbRef.pragma('optimize');
4343
dbRef.close();

0 commit comments

Comments
 (0)