My company is just completing the update from Mongoid 3.x to Mongoid 5.2 along with Rails. Things have generally gone well, but for an intermittent failure around server availability.
The error:
Mongo::Error::NoServerAvailable:
No server is available matching preference: #<Mongo::ServerSelector::Primary:0x70251562886840 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015
For our development and test environments, we run against a single/standalone instance of mongodb (ver 2.6 if that matters) on the same machine. On occasion (and randomly) an Mongo::Error::NoServerAvailable is raised. The location is random, but it seems to generally be on an action involving one of a few special case models in our app. These are models in our app in which we specify (via with(read: { mode: primary_preferred }) # or :primary ) to retrieve from the primary instance for best consistency.
The failure seems completely random, we can have multiple spec runs with no failure, and some runs with 1 or more failures in a random piece of test code. As best we can tell, the mongodb instances does not shutdown/restart while specs are running so there must be some other contributing factor. This gives us concerns that when we go to production we could continue to experience the issue which would provide for a poor experience for users.
Would really love to find a solution for this as we've already spent 3+ weeks doing the rails and mongo upgrades
Happy to provide any other information on request. I am hoping it's just a setting that can be adjusted or the like.
Thanks
- mike