From fd40049dfa978dffa0095798e2697c71a02cfdff Mon Sep 17 00:00:00 2001 From: Elin Angelow Date: Thu, 21 Dec 2023 17:40:55 +0200 Subject: [PATCH] fix: catch not released tx --- lib/postgres/index.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/postgres/index.js b/lib/postgres/index.js index e0459c8..9904eec 100644 --- a/lib/postgres/index.js +++ b/lib/postgres/index.js @@ -106,24 +106,27 @@ module.exports = async(config) => { } return arguments[name]; }); - if (!txId) { - const res = await link.query(`SELECT * FROM ${sqlName}(${fillArgs})`, dynArgs); + try { + if (!txId) { + const res = await link.query(`SELECT * FROM ${sqlName}(${fillArgs})`, dynArgs); + return res; + } + if (!txMap.get(txId)) { + throw SqlSe.create( + 'transactionIdNotFound', + {fn: jsName, argument: name, txId} + ); + } + const res = await txMap.get(txId).query(`SELECT * FROM ${sqlName}(${fillArgs})`, dynArgs); return res; + } catch (e) { + throw e; } - if (!txMap.get(txId)) { - throw SqlSe.create( - 'transactionIdNotFound', - {fn: jsName, argument: name, txId} - ); - } - const res = await txMap.get(txId).query(`SELECT * FROM ${sqlName}(${fillArgs})`, dynArgs); - return res; } }; }, {}); }; const methods = await build(); - return { methods, async stop() { @@ -145,6 +148,7 @@ module.exports = async(config) => { async txEnd(id, action) { const client = txMap.get(id); await client.query(action); + client.release(); txMap.delete(id); } };