Skip to content

Commit

Permalink
fix: ignore CLI0106E error for endTransaction, issue #938
Browse files Browse the repository at this point in the history
  • Loading branch information
bimalkjha committed Aug 15, 2023
1 parent 89d72b1 commit aca3359
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/odbc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,13 +1190,13 @@ Database.prototype.endTransactionSync = function (rollback)
{
var self = this;

self.conn.inTransaction = false;
try {
self.conn.endTransactionSync(rollback);
} catch (e) {
self.checkConnectionError(e);
throw new Error(e);
}
self.conn.inTransaction = false;

return self;
};
Expand Down Expand Up @@ -2719,7 +2719,11 @@ Database.prototype.poolCloseSync = function ()
// the pool. So that, next request can get afresh connection from pool.
if(db.conn && db.conn.inTransaction)
{
try {
db.rollbackTransactionSync();
} catch(error) {
// Just ignore the error, since we're closing the connection.
}
}

//remove this db from the usedPool
Expand All @@ -2737,7 +2741,7 @@ Database.prototype.poolCloseSync = function ()

if(db.conn && self.options.autoCleanIdle) self.cleanUp(connStr);
return self.queue.next();
}; // db.closeSync function
}; // db.poolCloseSync function

// conn.close function for pooled connection.
Database.prototype.poolClose = function (cb)
Expand Down
2 changes: 2 additions & 0 deletions test/test-pool-stale-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var timer = setInterval(function() {
console.log("Connection " + err.toString());
}

connection.beginTransactionSync();
connection.query("select 1 from sysibm.sysdummy1",
function (err, results) {
if (err) {
Expand All @@ -37,6 +38,7 @@ var timer = setInterval(function() {
}else{
console.log(JSON.stringify(results));
assert.equal(JSON.stringify(results), '[{"1":1}]');
connection.commitTransactionSync();
}
connection.close(function () {
console.log('Connection closed');
Expand Down

0 comments on commit aca3359

Please sign in to comment.