MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Java driver with Replica Set: not master and slaveOk=false

Hello,

I wasn’t sure if this is the correct section to post this in, so apologies if it’s wrong here.

We run several application components which use the MongoDB Java Driver 3.12.1 to connect to a PSA replica set running MongoDB 4.2.6. In fact, we run one production environment and several similar staging environments.

Last night, on one of the staging environments, one of the application components threw the following exception and then hung:

com.mongodb.MongoQueryException: Query failed with error code 13435 and error message 'not master and slaveOk=false' on server [secondary]

We are fairly sure that the MongoDB Primary did not step down, so there was no failover. But it looks like this component tried to work on the Secondary and thus failed. All components have all MongoDB hosts configured, i.e. Primary, Secondary and Arbiter, for their DB connection. Also, the application is not written to ever read from the secondary, for example. It’s always supposed to talk to the Primary.

The application exists since MongoDB 3.2 or even 3.0, so it’s fairly old. And we have done stepDowns and failovers many times, for upgrades and so on. But we have never seen this effect before. Is there anything that could cause this? We’re not too concerned at this point, because it has only happened once and not on production, but we’re still curious what could cause this. So I’d be thankful for any ideas. :slight_smile:

Regards
Frank

Hi Frank,

It might turn out to be helpful to have the full stack trace, including any chained exceptions. Can you post it please?

Thanks,
Jeff

Hi Jeffrey,

thank you for your reply! Since my first post it has happened again and through more research I did find that there was in fact a failover and re-election. I suspect that it’s a resource problem on the MongoDB servers. So it doesn’t seem to be related to the driver. Sorry about not following up on that earlier. I think we can consider this solved.

Regards
Frank

Hi Frank,

More recent versions of the Java driver automatically retry read and write operations. This might help your application be more robust in the face of failovers and elections.

Regards,
Jeff