Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gracefully close pool connections #3180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: implement pool_connection end
dimov authored and dstankovd committed Nov 16, 2024
commit 203ee7200a2e2f05aed9e19b347e7775cb0ab1c8
4 changes: 2 additions & 2 deletions lib/base/pool.js
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ class BasePool extends EventEmitter {
}
for (let i = 0; i < this._allConnections.length; i++) {
connection = this._allConnections.get(i);
connection._realEnd(endCB);
connection.end(endCB);
}
}

@@ -200,7 +200,7 @@ class BasePool extends EventEmitter {
Date.now() - this._freeConnections.get(0).lastActiveTime >
this.config.idleTimeout)
) {
this._freeConnections.get(0)._realEnd();
this._freeConnections.get(0).end();
}
} finally {
this._removeIdleTimeoutConnections();
16 changes: 3 additions & 13 deletions lib/base/pool_connection.js
Original file line number Diff line number Diff line change
@@ -29,16 +29,9 @@ class BasePoolConnection extends BaseConnection {
this._pool.releaseConnection(this);
}

end() {
const err = new Error(
'Calling conn.end() to release a pooled connection is ' +
'deprecated. In next version calling conn.end() will be ' +
'restored to default conn.end() behavior. Use ' +
'conn.release() instead.',
);
this.emit('warn', err);
console.warn(err.message);
this.release();
end(callback) {
this._removeFromPool();
super.end(callback);
}

destroy() {
@@ -58,6 +51,3 @@ class BasePoolConnection extends BaseConnection {

BasePoolConnection.statementKey = BaseConnection.statementKey;
module.exports = BasePoolConnection;

// TODO: Remove this when we are removing PoolConnection#end
BasePoolConnection.prototype._realEnd = BaseConnection.prototype.end;