Skip to content

Commit

Permalink
fix(connection): timed out connections should not be half closed
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Nov 27, 2019
1 parent c3bafbe commit 850f4f5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/core/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Connection extends EventEmitter {
// Internal state
this.writeStream = null;
this.destroyed = false;
this.timedOut = false;

// Create hash method
const hash = crypto.createHash('sha1');
Expand Down Expand Up @@ -214,7 +215,7 @@ class Connection extends EventEmitter {
return;
}

if (options.force) {
if (options.force || this.timedOut) {
this.socket.destroy();
this.destroyed = true;
if (typeof callback === 'function') callback(null, null);
Expand Down Expand Up @@ -334,6 +335,7 @@ function timeoutHandler(conn) {
conn.logger.debug(`connection ${conn.id} for [${conn.address}] timed out`);
}

conn.timedOut = true;
conn.emit(
'timeout',
new MongoNetworkError(`connection ${conn.id} to ${conn.address} timed out`),
Expand Down

0 comments on commit 850f4f5

Please sign in to comment.