-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.0.2
-
Component/s: Core, MongoDB 3.4
-
Environment:Ubuntu, Docker, AWS
-
Empty show more show less
*BUG*
*EXPECTED BEHAVIOR*
When a Mongos server resets the reconnect event should fired on the connection.
*ACTUAL BEHAVIOR*
The reconnect event is never fired.
*STEP TO REPRODUCE*
1. I'm using a Mongos container
2. Simple connection:
import { MongoClient } from 'mongodb' const dburl = 'mongodb://YOURCONTAINERADRESS:27017/' MongoClient.connect( dburl, { reconnectTries: Number.MAX_VALUE, reconnectInterval: 1000 }, function(err, db) { db.on('close', () => console.log('closed')) db.on('reconnect', () => console.log('reconnect')) db.on('disconnect', () => console.log('disconnect')) } )
3. Restart the container
With the same code but on my local machine and doing: service mongod stop -> service mongod start the reconnect event is properly fired.
**POSSIBLE CAUSE**
After digging a bit I found out that in
mongodb-core/mongos.js
return reconnectProxies(self, self.disconnectedProxies, function() { if (self.state === DESTROYED || self.state === UNREFERENCED) return; // Are we connected ? emit connect event if (self.state === CONNECTING && options.firstConnect) { self.emit('connect', self); self.emit('fullsetup', self); self.emit('all', self); } else if (self.isConnected()) { self.emit('reconnect', self); } else if (!self.isConnected() && self.listeners('close').length > 0) { self.emit('close', self); } // Perform topology monitor topologyMonitor(self); });
the self.isConnected() is never true on a reconnection therefore the reconnect event is never emitted. This is because the connectedProxies array is alway empty at this point in time.
- depends on
-
NODE-1290 SDAM Refactor
- Development Complete
- is related to
-
NODE-1166 Failure to reconnect through mongos after abrupt replicaset primary failure
- Closed
-
NODE-1314 Client hangs on reconnect when partitioned from majority of replset
- Closed
-
NODE-1363 Unable to establish a connection to a MongoDB cluster after a connection between Primary and its peers was disrupted and then fixed
- Closed