Skip to content

Commit 04caeac

Browse files
committed
Avoid closing connections twice when driver is closed
When closed, driver purges all connections from the connection pool and then closes all connections stored in an internal array of all alive connections. First step is needed to close all connections that are idle in the connection pool. Second step is needed to close all connections that are active and checked out of the connection pool. Note that list of all connections contains both idle and active connections. Driver used to purge the pool at the same time as going over the list of all connections. This made it close some idle connections twice. It did not cause any issues but resulted in a bit weird logging where `Connection.close()` operation was logged twice. This commit fixes the problem by making driver first purge the pool and then go over the list of all connections to close them.
1 parent 46c36ff commit 04caeac

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/v1/driver.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,17 @@ class Driver {
238238
close() {
239239
this._log.info(`Driver ${this._id} closing`);
240240

241-
for (let connectionId in this._openConnections) {
242-
if (this._openConnections.hasOwnProperty(connectionId)) {
243-
this._openConnections[connectionId].close();
244-
}
241+
try {
242+
// purge all idle connections in the connection pool
245243
this._pool.purgeAll();
244+
} finally {
245+
// then close all connections driver has ever created
246+
// it is needed to close connections that are active right now and are acquired from the pool
247+
for (let connectionId in this._openConnections) {
248+
if (this._openConnections.hasOwnProperty(connectionId)) {
249+
this._openConnections[connectionId].close();
250+
}
251+
}
246252
}
247253
}
248254
}

0 commit comments

Comments
 (0)