Skip to content

Commit 4fef468

Browse files
authored
fix: Throw TransactionError if database was disconnected when issuing transaction command
Automatically reconnecting for an in-transaction queries is not supported, as we’d have to replay all previous queries and still risk inconsistency if any subsequently issued application queries depended on data previously read during the disconnected transaction. We’d *also* have to keep a log of all previously returned data to verify that it hasn’t changed when reissuing the command – an unacceptable overhead, particularly since applications must be able to handle transaction conflicts anyway and this patch just makes disconnects look like any other “please retry transaction” condition.
1 parent 0bd35e4 commit 4fef468

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

query/transaction.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class Transaction {
337337
this.#committed = true;
338338
}
339339
} catch (e) {
340-
if (e instanceof PostgresError) {
340+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
341341
throw new TransactionError(this.name, e);
342342
}
343343
throw e;
@@ -510,7 +510,7 @@ export class Transaction {
510510
try {
511511
return (await this.#executeQuery(query)) as QueryArrayResult<T>;
512512
} catch (e) {
513-
if (e instanceof PostgresError) {
513+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
514514
await this.commit();
515515
throw new TransactionError(this.name, e);
516516
}
@@ -612,7 +612,7 @@ export class Transaction {
612612
try {
613613
return (await this.#executeQuery(query)) as QueryObjectResult<T>;
614614
} catch (e) {
615-
if (e instanceof PostgresError) {
615+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
616616
await this.commit();
617617
throw new TransactionError(this.name, e);
618618
}
@@ -756,7 +756,7 @@ export class Transaction {
756756
try {
757757
await this.queryArray(`ROLLBACK ${chain_option ? "AND CHAIN" : ""}`);
758758
} catch (e) {
759-
if (e instanceof PostgresError) {
759+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
760760
await this.commit();
761761
throw new TransactionError(this.name, e);
762762
}
@@ -855,7 +855,7 @@ export class Transaction {
855855
try {
856856
await savepoint.update();
857857
} catch (e) {
858-
if (e instanceof PostgresError) {
858+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
859859
await this.commit();
860860
throw new TransactionError(this.name, e);
861861
}
@@ -875,7 +875,7 @@ export class Transaction {
875875
try {
876876
await savepoint.update();
877877
} catch (e) {
878-
if (e instanceof PostgresError) {
878+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
879879
await this.commit();
880880
throw new TransactionError(this.name, e);
881881
}

0 commit comments

Comments
 (0)