I noticed that some of my queries are failling in MongoDB with the MaxTimeMSExpired message. Upon further inspection, I noticed that the maxTimeMS of these queries are set to 1000:
However, I don’t set this value anywhere in my code:
This is happening only to some queries, and not all of them. I wasn’t able to find anything in common between queries with this problem. It also happens across multiple collections.
While researching, I found nothing that could help me.
Is this value being set automatically by Meteor, or does it come from somewhere else? How can I disable it?
I couldn’t find anything in the Meteor code that sets maxTimeMS.
Do you use any package for your collections or MongoDB operations?
If it’s for specific queries, you can try setting maxTimeMS to your find calls.
maxTimeMs Number
(Server only) If set, instructs MongoDB to set a time limit for this cursor’s operations. If the operation reaches the specified time limit (in milliseconds) without the having been completed, an exception will be thrown. Useful to prevent an (accidental or malicious) unoptimized query from causing a full collection scan that would disrupt other database users, at the expense of needing to handle the resulting error.
Also, an update, I found out that these queries with maxTimeMS set only happen on the secondary, and they’re copies of previous slow queries that happened on the primary.
With that, I suspect this comes from some kind of monitoring, maybe from Atlas or from Monti. I think it repeats slow queries to collect some data.
Anyway, I’m pretty sure this won’t be a problem for us since it doesn’t affect real queries nor the primary replica. Still, I’d like to know where this comes from. If you have any idea, I’d be happy to hear it