"Cursor not found" error on Enumeration

1,128 views
Skip to first unread message

Ettienne

unread,
Jan 14, 2014, 4:24:08 AM1/14/14
to mongodb...@googlegroups.com
I have written a console application that connects directly to Mongo and Traverses the entire DB to perform updates.

For some reason I get the same error every time on itteration 2288 (See stack trace below)
I have inspected the record via MongoVue and it appears OK and consistent with the rest.
I tried to add some try catch logic to see if its related to the specific record being deserialized however the itteration dies after the error is thrown.
Below is a cross section of the console output and the source.

Could this be related to a connection timeout or finite Cursor lifetime?
In other attempts to troubleshoot
I have

- Changed the code from a Linq Statement to a Enumerator and added try catch.
- Looked around for where to apply this reference I found elsewhere in stack overflow? // cursor.SetFlags(QueryFlags.NoCursorTimeout);??
- updated mongo db to version 2.4.9
- upgraded to version 1.8.3.9 of the c# driver.


Any help will be appreciated



Processing document #2276 4fd07744e178a26bac456911
Processing document #2277 4fd0774ae178a26bac45691d
Processing document #2278 4fd0775ae178a26bac456933
Processing document #2279 4fd0775de178a26bac45693a
Processing document #2280 4fd07764e178a26bac456944
Processing document #2281 4fd07767e178a26bac456947
Processing document #2282 4fd0776ae178a26bac45694d
Processing document #2283 4fd07770e178a26bac456959
Processing document #2284 4fd07774e178a26bac45695c
Processing document #2285 4fd07777e178a26bac456962
Processing document #2286 4fd07779e178a26bac456965
Processing document #2287 4fd07783e178a26bac45697b
Processing document #2288 4fd07786e178a26bac45697e
Cursor not found.    at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(Bso
nBuffer buffer, IBsonSerializationOptions serializationOptions)
   at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBina
ryReaderSettings readerSettings, IBsonSerializer serializer, IBsonSerializationO
ptions serializationOptions)
   at MongoDB.Driver.Operations.QueryOperation`1.GetNextBatch(IConnectionProvide
r connectionProvider, Int64 cursorId)
   at MongoDB.Driver.Operations.QueryOperation`1.<Execute>d__0.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at ZeroPaper.OCR.Console.OCRConsole.Main(String[] args)
Processing document #2289 4fd07786e178a26bac45697e




using (MongoDocumentProvider mdp = new MongoDocumentProvider())
{
    using (DocumentSecurityDisabler dsd = new DocumentSecurityDisabler())
    {
        int currentIndex = 0;
        int counter = 0;
        var docs = mdp.GetDocumentList(true);
        var enumerate = docs.GetEnumerator();
      
        bool traverse = true;
        while(traverse)
        {
            try
            {
                if (enumerate.Current != null)
                {
                    System.Console.WriteLine("Processing document #" + currentIndex + " " + enumerate.Current.OID);
                    enumerate.Current.Name = enumerate.Current.GetRegexName();
                    mdp.SaveDocument(enumerate.Current);
                }
                traverse = enumerate.MoveNext();
              
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message + " " + ex.StackTrace);
            }
            currentIndex++;
            if (currentIndex > 999999) { traverse = false; };
        }
    }
}

Sinan Baran

unread,
Jan 14, 2014, 4:43:55 AM1/14/14
to mongodb...@googlegroups.com
  while (enumerate.MoveNext())

--
You received this message because you are subscribed to the Google Groups "mongodb-csharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-cshar...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sinan Baran

unread,
Jan 14, 2014, 4:45:05 AM1/14/14
to mongodb...@googlegroups.com
while (enumerate.MoveNext())
  {

Sinan Baran

unread,
Jan 14, 2014, 4:45:33 AM1/14/14
to mongodb...@googlegroups.com

            while (enumerate.MoveNext())
            {


            }


On Tue, Jan 14, 2014 at 11:24 AM, Ettienne <ettien...@hotmail.com> wrote:

--

Ettienne

unread,
Jan 14, 2014, 5:28:24 AM1/14/14
to mongodb...@googlegroups.com
Hi Sinan,

My original code had that structure with the movenext at the top of the while loop.
The reason I refactored it was an attempt to wrap each itteration in a try catch and not exit the itteration if one fetch fails.
The code as you outlined had the same issue as my current code.

craiggwilson

unread,
Jan 14, 2014, 10:50:18 AM1/14/14
to mongodb...@googlegroups.com
Are you using sharding?  How long does it take to process a single document?

Ettienne

unread,
Jan 14, 2014, 5:00:33 PM1/14/14
to mongodb...@googlegroups.com
Hi Craig,
No I am not using sharding this is a single instance of mongo running on the same box as the console app.
It processes each of these docs in under 500ms.

craiggwilson

unread,
Jan 15, 2014, 11:39:06 AM1/15/14
to mongodb...@googlegroups.com
So, the only reason a cursor would not be found if you aren't using sharding is if it takes longer than 10 minutes to process each batch.  At 500ms a document, that is 2 documents a second, 120 documents a minute, and 1200 documents every 10 minutes.  You can try to make the batch size smaller such that you'll go back to the server more often and therefore the cursor won't get collected.  Try calling SetBatchSize(100) on your cursor.
Reply all
Reply to author
Forward
0 new messages