Skip to content

Commit

Permalink
Only callback after the connection is released
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Nov 1, 2019
1 parent 50000d6 commit 4223d35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
15 changes: 7 additions & 8 deletions lib/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ Oracle.prototype.executeSQL = function(sql, params, options, callback) {
}

if (!err && data) {
const lobs = [];
if (data.rows) {
data = data.rows;
if (self.settings.debug && data) {
Expand All @@ -255,15 +254,15 @@ Oracle.prototype.executeSQL = function(sql, params, options, callback) {
releaseConnectionAndCallback();

function releaseConnectionAndCallback() {
connection.release(function(err) {
if (err) {
self.debug(err);
connection.release(function(err2) {
if (err2) {
self.debug(err2);
}
if (self.settings.debug) {
self.debug('Connection released: ', self.pool);
}
callback(err || err2, data);
});
if (self.settings.debug) {
self.debug('Connection released: ', self.pool);
}
callback(err ? err : null, data ? data : null);
}
});
});
Expand Down
14 changes: 13 additions & 1 deletion test/oracle.connectionpool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Oracle connector', function() {
});
});

it('should create connection pool ', function(done) {
it('should create connection pool with config', function(done) {
config.minConn = 2;
config.maxConn = 4;
config.incrConn = 2;
Expand Down Expand Up @@ -68,4 +68,16 @@ describe('Oracle connector', function() {
});
});
});

it('should close connection pool gracefully', function(done) {
db = new DataSource(require('../'), config);
db.connect(function() {
// Call ping to acquire/release a connection from the pool
db.ping(function(err) {
if (err) return done(err);
// It should disconnect gracefully
db.disconnect(done);
});
});
});
});

0 comments on commit 4223d35

Please sign in to comment.