Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixing exception when reopening a replica set #1263

Closed
wants to merge 2 commits into from

2 participants

@ethankan

I was attempting to reconnect to a replica set after disconnecting, but the native driver is throwing exceptions. I made a minor fix so that this is possible.

@aheckmann
Owner

Looks good. Please add a regression test.

@ethankan

Let me know if the test case I added is sufficient. Thanks!

@aheckmann
Owner

merged, thanks!

@aheckmann aheckmann closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 29, 2012
  1. @ethankan
Commits on Dec 30, 2012
  1. @ethankan
This page is out of date. Refresh to see the latest.
View
6 lib/drivers/node-mongodb-native/connection.js
@@ -94,10 +94,10 @@ function listen (conn) {
*/
NativeConnection.prototype.doOpenSet = function (fn) {
- if (!this.db) {
- var servers = []
- , self = this
+ var servers = []
+ , self = this;
+ if (!this.db) {
this.hosts.forEach(function (server) {
var host = server.host || server.ipc;
var port = server.port || 27017;
View
23 test/connection.test.js
@@ -685,6 +685,29 @@ describe('connections:', function(){
db.close();
done();
})
+
+ it('can reopen a disconnected replica set', function(done) {
+ var uris = process.env.MONGOOSE_SET_TEST_URI;
+ if (!uris) return done();
+
+ var conn = mongoose.createConnection();
+
+ conn.on('error', done);
+
+ try {
+ conn.openSet(uris, 'mongoose_test', {}, function(err) {
+ if (err) return done(err);
+
+ conn.close(function(err) {
+ if (err) return done(err);
+
+ conn.openSet(uris, 'mongoose_test', {}, done);
+ });
+ });
+ } catch (err) {
+ done(err);
+ }
+ })
})
})
Something went wrong with that request. Please try again.