Skip to content

Commit d5753f8

Browse files
committed
rename pooled connection end to release
1 parent c87ba17 commit d5753f8

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

lib/Pool.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Pool.prototype.end = function (cb) {
116116
for (var i = 0; i < this._allConnections.length; i++) {
117117
connection = this._allConnections[i];
118118

119+
delete connection.release;
119120
connection.destroy = connection._realDestroy;
120121
connection.end = connection._realEnd;
121122
connection.end(endCB);
@@ -132,7 +133,7 @@ Pool.prototype.query = function (sql, values, cb) {
132133
if (err) return cb(err);
133134

134135
conn.query(sql, values, function () {
135-
conn.end();
136+
conn.release();
136137
cb.apply(this, arguments);
137138
});
138139
});
@@ -146,10 +147,19 @@ Pool.prototype._createConnection = function() {
146147

147148
connection._realEnd = connection.end;
148149
connection.end = function(cb) {
149-
self.releaseConnection(connection);
150+
console.warn( 'Calling conn.end() to release a pooled connection is '
151+
+ 'deprecated. In next version calling conn.end() will be '
152+
+ 'restored to default conn.end() behavior. Use '
153+
+ 'conn.release() instead.'
154+
);
155+
this.release();
150156
if (cb) cb();
151157
};
152158

159+
connection.release = function () {
160+
self.releaseConnection(connection);
161+
};
162+
153163
connection._realDestroy = connection.destroy;
154164
connection.destroy = function() {
155165
self._removeConnection(connection);
@@ -198,6 +208,7 @@ Pool.prototype._removeConnection = function(connection) {
198208
}
199209
}
200210

211+
delete connection.release;
201212
connection.end = connection._realEnd;
202213
connection.destroy = connection._realDestroy;
203214

test/integration/pool/test-connection-limit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ pool.getConnection(function(err, connection) {
2121
});
2222

2323
shouldGetConnection = true;
24-
connection.end();
24+
connection.release();
2525
});
2626
});

test/integration/pool/test-destroy-connection.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pool.getConnection(function(err, connection) {
1111
assert.ok(pool._allConnections.length == 0);
1212
assert.ok(connection._poolRemoved);
1313
assert.strictEqual(connection.end, Connection.prototype.end);
14-
assert.strictEqual(connection.destroy, Connection.prototype.destroy);
14+
assert.strictEqual(connection.end, Connection.prototype.end);
15+
assert.ok(!('release' in connection))
1516

1617
pool.end();
1718
});

test/integration/pool/test-queue-limit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ var pool = common.createPool({
88

99
// First connection we get right away
1010
pool.getConnection(function(err, connection) {
11-
connection.end()
11+
connection.release()
1212
})
1313

1414
// Second connection request goes into the queue
1515
pool.getConnection(function(err, connection) {
16-
connection.end()
16+
connection.release()
1717
pool.end()
1818
})
1919

0 commit comments

Comments
 (0)