diff --git a/backend/src/database.ts b/backend/src/database.ts index 21d90261d..a9893fdac 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -72,6 +72,15 @@ import { execSync } from 'child_process'; } } + private async $rollbackAtomic(connection: PoolConnection): Promise { + try { + await connection.rollback(); + await connection.release(); + } catch (e) { + logger.warn('Failed to rollback incomplete db transaction: ' + (e instanceof Error ? e.message : e)); + } + } + public async $atomicQuery(queries: { query, params }[]): Promise<[T, FieldPacket[]][]> { @@ -90,9 +99,8 @@ import { execSync } from 'child_process'; return results; } catch (e) { - logger.err('Could not complete db transaction, rolling back: ' + (e instanceof Error ? e.message : e)); - connection.rollback(); - connection.release(); + logger.warn('Could not complete db transaction, rolling back: ' + (e instanceof Error ? e.message : e)); + this.$rollbackAtomic(connection); throw e; } finally { connection.release();