Reconnect Issues with Replica Sets

142 views
Skip to first unread message

Evan Leichter

unread,
May 8, 2014, 11:34:54 AM5/8/14
to node-mong...@googlegroups.com
I'm having some trouble getting the driver to reconnect to a replica set.  Specifically, I find that if I issue a write command to the database (like collection.update) while the mongo host is down, the connection gets destroyed by the driver, and the driver doesn't try to reestablish it when the host goes back up.

This is what I'm doing:
  1. Connect my node server to a mongo replica set with 1 member (yes, I know this is not a good replica set configuration, but this is just a test situation).  When connecting, I specificy auto_reconnect: true and bufferMaxEntries: 0.
  2. Successfully call collection.update().
  3. Stop mongod process (service mongod stop).
  4. Call collection.update() again from the node server.  This fails immediately with the error "No connection operations buffering limit of 0 reached".
  5. Restart the mongod process (service mongod restart), and verify that it starts up successfully and becomes the primary.
  6. Call collection.update() again from the node server.  This, and all future calls to the database (reads or writes) from this connection, fail with the error "Connection was destroyed by application".  Unless I restart the node server, at which point the connection is reestablished properly.
This also seems to only affect write commands; if I go through the same process but use commands like collection.findOne() instead, they will start working again after the mongo host is back up.

Is this an issue with the driver?  Or am I misusing some of connection options?

Also I realize the process I presented here is a bit of a contrived situation.  However, a similar problem manifested in our semi-live staging environment that I believe has the same root cause: when reconfiguring a replica set, mongo forced a disconnect on all the connections our node servers made to it.  Before the connection could be reestablished, the node servers attempted to update some objects in the database, and this caused the connections to get destroyed.

Thanks for your help!
Evan Leichter
Reply all
Reply to author
Forward
0 new messages