Skip to content

Commit

Permalink
fix: catch not released tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Elin Angelow committed Dec 21, 2023
1 parent 38f20c8 commit fd40049
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
};
Expand Down

0 comments on commit fd40049

Please sign in to comment.