orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift

Home Page:https://orlandos.nl/docs/mongokitten/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NotMasterNoSlaveOk

valeriomazzeo opened this issue · comments

I keep randomly getting this error, not sure what could be the cause:

MongoKitten.MongoError.invalidResponse([{\"ok\":0.0,\"codeName\":\"NotMasterNoSlaveOk\",\"errmsg\":\"not master and slaveOk=false\",\"code\":13435}])

Environment:

  • Mongodb 3.4.14 (Cloud Atlas)
  • MongoKitten 4.0.19

@valeriomazzeo It seems MongoKitten sent a query to one of the slaves. This is only possible for read queries where slaveOK is explicitly true. MongoKitten never sets slaveOK to true, so that explains the error. What query were you running?

I am not sure, as I was using Fluent, so this must be coming from the driver.
Also, restarting the web server fixed the issue. Any idea?

Yes. Your primary MongoDB server's node's connection went offline for whatever reason and MongoKitten (had to) switch to a secondary node. Probably picked the wrong one.

ok, so how could we prevent this to happen or to properly recover?

You can shutdown MongoKitten's server object and it'll reconnect the next query.

I suppose when using mongo-driver with fluent it should be the driver to take care of this?

The Fluent driver, yes.

I'm closing this, since it's a Fluent issue.