5

Does anybody know how to add in a timeout for queries on the server side of MongoDb? Not a client side timeout (I am using the C# driver). I have a problem where the client crashes, and the connection to Mongo dies, but the server continues to execute queries. This causes a huge buildup of needless/outdated queries in the server's queue.

4
  • can you add an example of the queries you are running - are you setting any write safety options? Something that's a little unclear - if the connection goes away, then where are the new queries coming from, or is it only for a certain amount of time that the queries continue? Commented Feb 16, 2012 at 10:49
  • 1
    @AdamC: there might be a veeeery long running query, and, even if connection dies, it keeps running, blocking other queries, despite the fact that no one want its result. I had a couple of these. Commented Feb 16, 2012 at 11:16
  • @Sergio got it right. I have multiple clients contacting the server at any given time. X sends a complicated query to the db and subsequently crashes... the server keeps executing that query even though its connection to X has ended. Commented Feb 16, 2012 at 14:40
  • hmm, quite a few queries have no action in terms of a return in MongoDB - an insert/update for example - the fact that the client goes away has no impact on the query's behavior....I think I have a potential answer though - will post below Commented Feb 16, 2012 at 15:10

1 Answer 1

1

If you have these long running queries from a prior client connection that you want to stop/kill, then you would need to either manually kill them per:

http://www.mongodb.org/display/DOCS/Viewing+and+Terminating+Current+Operation

Or, at the startup of your new client you could do something more programmatic (get last run queries from a log, kill them because they are from the previous client). Whether you can programmatically identify the operations you want to kill and avoid killing others is the key here - may require you to add some logging in your app to track in-flight operation.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, probably we can do that, but instead of checking in cron result of db.currentOp() for operations where secs_running is greater that, let say, 600 I'd like mongo DB engine to kill such queries...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.