Skip to content

Commit a2f1b21

Browse files
committed
refactor(pool): wait for createConnection on pool reset
1 parent ff733b3 commit a2f1b21

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/core/connection/pool.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ function resetPoolState(pool) {
241241

242242
function connectionFailureHandler(pool, event, err, conn) {
243243
if (conn) {
244-
if (conn._connectionFailHandled) return;
244+
if (conn._connectionFailHandled) {
245+
return;
246+
}
247+
245248
conn._connectionFailHandled = true;
246249
conn.destroy();
247250

@@ -430,7 +433,7 @@ function messageHandler(self) {
430433
updateSessionFromResponse(session, document);
431434
}
432435

433-
if (document.$clusterTime) {
436+
if (self.topology && document.$clusterTime) {
434437
self.topology.clusterTime = document.$clusterTime;
435438
}
436439
}
@@ -752,11 +755,12 @@ Pool.prototype.reset = function(callback) {
752755

753756
resetPoolState(this);
754757

755-
// attempt reexecution
756-
process.nextTick(() => _execute(this)());
757-
if (typeof callback === 'function') {
758-
callback(null, null);
759-
}
758+
// create a new connection, this will ultimately trigger execution
759+
createConnection(this, () => {
760+
if (typeof callback === 'function') {
761+
callback(null, null);
762+
}
763+
});
760764
}
761765
);
762766
};
@@ -877,10 +881,6 @@ Pool.prototype.write = function(command, options, cb) {
877881
// Optional per operation socketTimeout
878882
operation.socketTimeout = options.socketTimeout;
879883
operation.monitoring = options.monitoring;
880-
// Custom socket Timeout
881-
if (options.socketTimeout) {
882-
operation.socketTimeout = options.socketTimeout;
883-
}
884884

885885
// Get the requestId
886886
operation.requestId = command.requestId;

0 commit comments

Comments
 (0)