-
Type:
Bug
-
Resolution: Done
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 1.4.39, 2.0.52
-
Component/s: None
-
Environment:Ubuntu 14.04, Mongo 2.4.10, Node 0.10.24
-
None
-
None
-
None
-
None
-
None
-
None
-
None
I'm running into issues auto-reconnecting to a replica set when I attempt to create multiple databases using the same underlying connections (using db.db() ).
Basically, I'm connecting + authenticating to one database in a replica set with the auto_reconnect flag set to true, creating a second database sharing that connection, and then manually calling db.authenticate() on that second database. This works, and commands run on both databases work. However, if the client disconnects from the replSet (e.g. the primary mongod process is stopped + restarted), when it attempts to reconnect, it does not authenticate to the database successfully. In the mongo logs I see a bunch of "auth: bad nonce received or getnonce not called." errors, and attempting to run queries on the databases gives me in "not authorized for query" errors.
I've gotten this error in driver versions 1.4.39 and the latest 2.0.52. My database is mongo version 2.4.10.
Auto-reconnecting works fine if I don't create + auth a second db off the initial connection.
Some sample code:
var mongodb = require('mongodb'), connUrl = 'mongodb://fakeUser:fakePassword@33.33.33.100:27017,127.0.0.1:27017/testDb?replicaSet=devReplSet';, opts = { server: { auto_reconnect: true }, db: { native_parser: true, bufferMaxEntries: 0 } }; mongodb.MongoClient.connect(connUrl, opts, function(err, db) { if (err) throw err; var otherDb = db.db('otherDb'); otherDb.authenticate('fakeUser', 'fakePassword', function(err, result) { if (err) throw err; db.collection('foo').findOne(console.log); // succeeds, prints item otherDb.collection('bar').findOne(console.log); // succeeds, prints item // restart primary mongod process // wait for primary to be re-elected db.collection('foo').findOne(console.log); // fails with error 'not authorized for query on testDb.foo' otherDb.collection('bar').findOne(console.log); // fails with error 'not authorized for query on otherDb.bar' }); });