Skip to content

Commit

Permalink
fix: use serverDescriptionChanged event to distinguish between timeou…
Browse files Browse the repository at this point in the history
…t vs disconnected re: #8383
  • Loading branch information
vkarpov15 committed Nov 28, 2019
1 parent 9f0a9a9 commit ca527f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/connection.js
Expand Up @@ -677,15 +677,16 @@ Connection.prototype.openUri = function(uri, options, callback) {
server.s.pool.on('reconnect', () => {
_handleReconnect();
});
server.s.pool.on('timeout', () => {
_this.emit('timeout');
});
client.on('serverClosed', () => {
_this.readyState = STATES.disconnected;
});
server.s.pool.on('drain', err => {
if (err && err.name === 'MongoNetworkError' && err.message.endsWith('timed out')) {
client.on('serverDescriptionChanged', ev => {
const newDescription = ev.newDescription;
if (newDescription.type === 'Standalone') {
_handleReconnect();
} else if (newDescription.error != null &&
newDescription.error.name === 'MongoNetworkError' &&
newDescription.error.message.endsWith('timed out')) {
_this.emit('timeout');
} else {
_this.readyState = STATES.disconnected;
}
});
} else if (type.startsWith('ReplicaSet')) {
Expand Down
1 change: 0 additions & 1 deletion test/connection.test.js
Expand Up @@ -341,7 +341,6 @@ describe('connections:', function() {
});

conn.on('disconnected', function() {
console.log('Disconnected', new Error().stack);
++numDisconnected;
});

Expand Down

0 comments on commit ca527f4

Please sign in to comment.