Skip to content

Commit c7a64f3

Browse files
committed
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 c537bbd commit c7a64f3

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
@@ -339,7 +339,7 @@ export class Transaction {
339339
this.#committed = true;
340340
}
341341
} catch (e) {
342-
if (e instanceof PostgresError) {
342+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
343343
throw new TransactionError(this.name, e);
344344
}
345345
throw e;
@@ -512,7 +512,7 @@ export class Transaction {
512512
try {
513513
return (await this.#executeQuery(query)) as QueryArrayResult<T>;
514514
} catch (e) {
515-
if (e instanceof PostgresError) {
515+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
516516
await this.commit();
517517
throw new TransactionError(this.name, e);
518518
}
@@ -614,7 +614,7 @@ export class Transaction {
614614
try {
615615
return (await this.#executeQuery(query)) as QueryObjectResult<T>;
616616
} catch (e) {
617-
if (e instanceof PostgresError) {
617+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
618618
await this.commit();
619619
throw new TransactionError(this.name, e);
620620
}
@@ -758,7 +758,7 @@ export class Transaction {
758758
try {
759759
await this.queryArray(`ROLLBACK ${chain_option ? "AND CHAIN" : ""}`);
760760
} catch (e) {
761-
if (e instanceof PostgresError) {
761+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
762762
await this.commit();
763763
throw new TransactionError(this.name, e);
764764
}
@@ -857,7 +857,7 @@ export class Transaction {
857857
try {
858858
await savepoint.update();
859859
} catch (e) {
860-
if (e instanceof PostgresError) {
860+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
861861
await this.commit();
862862
throw new TransactionError(this.name, e);
863863
}
@@ -877,7 +877,7 @@ export class Transaction {
877877
try {
878878
await savepoint.update();
879879
} catch (e) {
880-
if (e instanceof PostgresError) {
880+
if (e instanceof PostgresError || e instanceof Deno.errors.BrokenPipe) {
881881
await this.commit();
882882
throw new TransactionError(this.name, e);
883883
}

0 commit comments

Comments
 (0)