Fix sequencing of database closes
This commit is contained in:
parent
a795ae6157
commit
ab1ae26489
1 changed files with 11 additions and 10 deletions
|
@ -642,25 +642,18 @@ async function initialize({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function close(): Promise<void> {
|
async function close(): Promise<void> {
|
||||||
|
globalReadonlyInstance?.close();
|
||||||
|
globalReadonlyInstance = undefined;
|
||||||
|
|
||||||
// SQLLite documentation suggests that we run `PRAGMA optimize` right
|
// SQLLite documentation suggests that we run `PRAGMA optimize` right
|
||||||
// before closing the database connection.
|
// before closing the database connection.
|
||||||
globalWritableInstance?.pragma('optimize');
|
globalWritableInstance?.pragma('optimize');
|
||||||
|
|
||||||
globalWritableInstance?.close();
|
globalWritableInstance?.close();
|
||||||
globalWritableInstance = undefined;
|
globalWritableInstance = undefined;
|
||||||
globalReadonlyInstance?.close();
|
|
||||||
globalReadonlyInstance = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeDB(): Promise<void> {
|
async function removeDB(): Promise<void> {
|
||||||
if (globalWritableInstance) {
|
|
||||||
try {
|
|
||||||
globalWritableInstance.close();
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('removeDB: Failed to close database:', error.stack);
|
|
||||||
}
|
|
||||||
globalWritableInstance = undefined;
|
|
||||||
}
|
|
||||||
if (globalReadonlyInstance) {
|
if (globalReadonlyInstance) {
|
||||||
try {
|
try {
|
||||||
globalReadonlyInstance.close();
|
globalReadonlyInstance.close();
|
||||||
|
@ -669,6 +662,14 @@ async function removeDB(): Promise<void> {
|
||||||
}
|
}
|
||||||
globalReadonlyInstance = undefined;
|
globalReadonlyInstance = undefined;
|
||||||
}
|
}
|
||||||
|
if (globalWritableInstance) {
|
||||||
|
try {
|
||||||
|
globalWritableInstance.close();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('removeDB: Failed to close database:', error.stack);
|
||||||
|
}
|
||||||
|
globalWritableInstance = undefined;
|
||||||
|
}
|
||||||
if (!databaseFilePath) {
|
if (!databaseFilePath) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'removeDB: Cannot erase database without a databaseFilePath!'
|
'removeDB: Cannot erase database without a databaseFilePath!'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue