diff --git a/app/gen-server/lib/TypeORMPatches.ts b/app/gen-server/lib/TypeORMPatches.ts index 6c13d009..12f1bc1a 100644 --- a/app/gen-server/lib/TypeORMPatches.ts +++ b/app/gen-server/lib/TypeORMPatches.ts @@ -13,6 +13,7 @@ // changed during construction of a query. import * as sqlite3 from '@gristlabs/sqlite3'; +import * as log from 'app/server/lib/log'; import {Mutex, MutexInterface} from 'async-mutex'; import isEqual = require('lodash/isEqual'); import {EntityManager, QueryRunner} from 'typeorm'; @@ -102,6 +103,7 @@ export function applyPatch() { await queryRunner.commitTransaction(); return result; } catch (err) { + log.debug(`SQLite transaction error [${arg1} ${arg2}] - ${err}`); try { // we throw original error even if rollback thrown an error await queryRunner.rollbackTransaction(); diff --git a/app/server/lib/dbUtils.ts b/app/server/lib/dbUtils.ts index 6a81dcec..facfa162 100644 --- a/app/server/lib/dbUtils.ts +++ b/app/server/lib/dbUtils.ts @@ -55,8 +55,12 @@ export async function getOrCreateConnection(): Promise { // If multiple servers are started within the same process, we // share the database connection. This saves locking trouble // with Sqlite. - return getConnection(); + const connection = getConnection(); + return connection; } catch (e) { + if (!String(e).match(/ConnectionNotFoundError/)) { + throw e; + } const connection = await createConnection(); // When using Sqlite, set a busy timeout of 3s to tolerate a little // interference from connections made by tests. Logging doesn't show