From c91ab7505432997e7d765b4f866ff60030ec4796 Mon Sep 17 00:00:00 2001 From: John Conley Date: Mon, 13 Jun 2022 15:28:12 -0700 Subject: [PATCH 1/2] fix returning bad connection --- src/db/transaction.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/db/transaction.ts b/src/db/transaction.ts index edaf4cd..e8c39e6 100644 --- a/src/db/transaction.ts +++ b/src/db/transaction.ts @@ -91,6 +91,7 @@ export async function transaction( if (txnSeq >= Number.MAX_SAFE_INTEGER - 1) txnSeq = 0; // wrap around + let released = false; const txnId = txnSeq++, clientIsOurs = typeofQueryable(txnClientOrQueryable) === 'pool', @@ -140,9 +141,12 @@ export async function transaction( } } + } catch (err) { + if (clientIsOurs && !released) txnClient.release(err); + throw err; } finally { delete txnClient._zapatos; - if (clientIsOurs) txnClient.release(); + if (clientIsOurs && !released) txnClient.release(); } } From 1245663b96bcd3f90268b68fee27c6c2ba7bf4f9 Mon Sep 17 00:00:00 2001 From: John Conley Date: Mon, 13 Jun 2022 15:37:05 -0700 Subject: [PATCH 2/2] minor fix --- src/db/transaction.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/db/transaction.ts b/src/db/transaction.ts index e8c39e6..76db80b 100644 --- a/src/db/transaction.ts +++ b/src/db/transaction.ts @@ -142,7 +142,10 @@ export async function transaction( } } catch (err) { - if (clientIsOurs && !released) txnClient.release(err); + if (clientIsOurs && !released) { + txnClient.release(err); + released = true; + } throw err; } finally { delete txnClient._zapatos;