{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/8598","repository_url":"https://api.github.com/repos/meteor/meteor","labels_url":"https://api.github.com/repos/meteor/meteor/issues/8598/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/8598/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/8598/events","html_url":"https://github.com/meteor/meteor/issues/8598","id":221685191,"number":8598,"title":"Mongo connections don't auto-reconnect if \"replicaSet=...\" is in the connection URL","user":{"login":"veered","id":247408,"avatar_url":"https://avatars2.githubusercontent.com/u/247408?v=3","gravatar_id":"","url":"https://api.github.com/users/veered","html_url":"https://github.com/veered","followers_url":"https://api.github.com/users/veered/followers","following_url":"https://api.github.com/users/veered/following{/other_user}","gists_url":"https://api.github.com/users/veered/gists{/gist_id}","starred_url":"https://api.github.com/users/veered/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veered/subscriptions","organizations_url":"https://api.github.com/users/veered/orgs","repos_url":"https://api.github.com/users/veered/repos","events_url":"https://api.github.com/users/veered/events{/privacy}","received_events_url":"https://api.github.com/users/veered/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-04-13T21:18:43Z","updated_at":"2017-06-29T16:36:00Z","closed_at":null,"body":"Using the `replicaSet=...` option in `MONGO_URL` or `MONGO_OPLOG_URL` causes auto-reconnects to be disabled on that connection. Since including this parameter is the officially recommended approach, most people using Meteor in prod don't have auto-reconnecting DB connections. I am using Meteor 1.4.3.2, but I think this bug has pretty much always existed.\r\n\r\nThe bug is very easy to reproduce. Locally set `MONGO_URL` to a mongo url that includes `replicaSet=...`. Open up the meteor shell and do a find on a collection; the query should successfully complete. Now reset the network connection on your computer. Try the query again; the query should hang and eventually fail. Now try this same series of steps after removing the `replicaSet` parameter from `MONGO_URL`; notice that the query won't fail. The steps for replicating the problem for `MONGO_OPLOG_URL` is exactly the same.\r\n\r\nNote: If removing the `replicaSet` parameter crashes your server, then make sure there is only a single host referenced in `MONGO_URL` and that this host is the primary. \r\n\r\nThe main thing going on here is that by passing in the `replSet` parameter the Mongo driver uses the `replset` connection type rather than the `server` connection type. As you can see [here](https://github.com/mongodb/node-mongodb-native/blob/2.2/lib/replset.js#L135) `replset` connections ignore the auto-reconnect property, but `server` connection types [do not](https://github.com/mongodb/node-mongodb-native/blob/2.2/lib/server.js#L129).\r\n\r\nYou can view info about the `MONGO_URL` connection by typing `Meteor.users._driver.mongo.db.serverConfig` into the meteor shell, and info about `MONGO_OPLOG_URL` by typing `Meteor.users._driver.mongo._oplogHandle._oplogTailConnection.db.serverConfig` into the meteor shell.\r\n\r\nThis may be due to a relatively recent change in the mongo driver that happened on June 14th, 2016. [Here is the commit](https://github.com/mongodb/node-mongodb-native/commit/412b50d53dc8e958d3b726fc7f66fe0447b9da66#diff-3995a38a37cf6b7ad44d4c8e63893046R131). But it is also possible that auto-reconnect was never supported for `replset` connections, and that commit is just refactoring the code to reflect that fact. Hard to tell exactly. In any case, it isn't supported anymore. \r\n\r\nSeems like this problem is related to a bunch of issues people have been having, #5773 being the most popular.\r\n\r\nNot really sure the best way to fix this. For now I've just dropped the `replicaSet` parameter and made sure that each connection URL only references the primary host, not the secondary. \r\n\r\nWhat is the purpose of passing in info about the secondary node (which is the only thing that is forcing us to use the `replicaSet` parameter)? It doesn't really seem to be used for anything except for failover support, and Meteor can't handle failover. I guess if you keep both hosts in the connection URL, Meteor will connect to the new primary upon restart.\r\n\r\nThe only solutions I can think of are:\r\n  (1) Stop passing in the `replicaSet` parameter\r\n  (2) Patch the mongo driver so that `replset` connections support auto-reconnects.\r\n  (3) Handle reconnects at the Meteor level\r\n\r\nAnyways, this is a pretty important bug. We had some serious outages over the past week because Compose reset all db connections a few times while debugging something unrelated on their end."},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/312022434","html_url":"https://github.com/meteor/meteor/issues/8598#issuecomment-312022434","issue_url":"https://api.github.com/repos/meteor/meteor/issues/8598","id":312022434,"user":{"login":"Siyfion","id":338488,"avatar_url":"https://avatars0.githubusercontent.com/u/338488?v=3","gravatar_id":"","url":"https://api.github.com/users/Siyfion","html_url":"https://github.com/Siyfion","followers_url":"https://api.github.com/users/Siyfion/followers","following_url":"https://api.github.com/users/Siyfion/following{/other_user}","gists_url":"https://api.github.com/users/Siyfion/gists{/gist_id}","starred_url":"https://api.github.com/users/Siyfion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Siyfion/subscriptions","organizations_url":"https://api.github.com/users/Siyfion/orgs","repos_url":"https://api.github.com/users/Siyfion/repos","events_url":"https://api.github.com/users/Siyfion/events{/privacy}","received_events_url":"https://api.github.com/users/Siyfion/received_events","type":"User","site_admin":false},"created_at":"2017-06-29T16:36:00Z","updated_at":"2017-06-29T16:36:00Z","body":"@abernix I only managed to reproduce this regularly because Compose.io were having issues with one of the hosts that I was using; whereby it was having network connectivity issues every ~24-36hrs for about 1-2 secs each time. I've since changed to not use a replication set, and also switched host servers on Compose.io. So it's not likely to re-occur now in production, though I believe @veered's instructions should work.\r\n\r\nI mean it's pretty trivial; set up a MongoDB server as part of a replication set, give a `MONGO_URL` connection string with more than one host, interrupt the connection, watch as it sits there doing nothing... :/"}}
{"actor":{"display_login":"Siyfion"}}