MongoException$CursorNotFound

407 views
Skip to first unread message

Need Help

unread,
Nov 3, 2015, 6:32:09 PM11/3/15
to mongodb-user
We are getting the cursor not found exception once in a while on production system on the cloud.  I have tried to reproduce the problem on our local server, but there seems to be no cursor timeout locally.

We used to set cursor to no timeout, but we ended up having many cursors open indefinitely.  Is there any way to make sure the cursor is always cleaned up manually? 

Also, does mongod --setParameter cursorTimeoutMillis=xxx work?  If we set the cursorTimeoutMillis to maybe 30 minutes or longer? 

Here is the log:
Caused by: com.mongodb.MongoException$CursorNotFound: Cursor 122927474452794 not found on server xxx.xxx.xxx.xxx:27017
        at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:250)
        at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:224)
        at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:184)
        at com.mongodb.QueryResultIterator.getMore(QueryResultIterator.java:149)
        at com.mongodb.QueryResultIterator.hasNext(QueryResultIterator.java:135)
        at com.mongodb.DBCursor._hasNext(DBCursor.java:626)
        at com.mongodb.DBCursor.hasNext(DBCursor.java:657)

Stephen Steneker

unread,
Nov 4, 2015, 11:44:08 PM11/4/15
to mongodb-user

On Wednesday, 4 November 2015 10:32:09 UTC+11, Need Help wrote:

We are getting the cursor not found exception once in a while on production system on the cloud. I have tried to reproduce the problem on our local server, but there seems to be no cursor timeout locally.

We used to set cursor to no timeout, but we ended up having many cursors open indefinitely. Is there any way to make sure the cursor is always cleaned up manually?

Also, does mongod —setParameter cursorTimeoutMillis=xxx work? If we set the cursorTimeoutMillis to maybe 30 minutes or longer?

Here is the log:

Caused by: com.mongodb.MongoException$CursorNotFound: Cursor 122927474452794 not found on server xxx.xxx.xxx.xxx:27017
at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:250)
at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:224)
at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:184)
at com.mongodb.QueryResultIterator.getMore(QueryResultIterator.java:149)
at com.mongodb.QueryResultIterator.hasNext(QueryResultIterator.java:135)
at com.mongodb.DBCursor._hasNext(DBCursor.java:626)
at com.mongodb.DBCursor.hasNext(DBCursor.java:657)

Hi,

What are your specific versions of MongoDB driver and server?

Unless you are setting the “notimeout” (aka “immortal”) option for cursors, they will automatically be closed when the results are exhausted or after the idle timeout (see: Closure of Inactive Cursors). The default idle timeout is 10 minutes, but you can adjust this with the cursorTimeoutMillis parameter in MongoDB 2.6.9+ or MongoDB 3.0.2+ (see SERVER-8188).

Regards,
Stephen

Need Help

unread,
Apr 21, 2016, 11:49:48 PM4/21/16
to mongodb-user
We'd like to set cursorTimeout to 30 minutes.  

Could you please tell me how to put that information into the configuration file?  

We are using mongodb 3.0.4

I tried to put the following into the configuration file mongod.conf, but it does not recognize cursorTimeoutMillis:
     cursorTimeoutMillis = 30000

I can start mongodb with the following command:
      mongod --setParameter cursorTimeoutMillis=30000 -f mongod.conf

However, when I check for db.serverStatus(), I do not see the cursorTimeoutMillis being set:
> db.serverStatus().metrics.cursor
{
        "timedOut" : NumberLong(0),
        "open" : {
                "noTimeout" : NumberLong(0),
                "pinned" : NumberLong(0),
                "total" : NumberLong(0)
        }
}

Thanks a lot for your help in advance!

Wan Bachtiar

unread,
May 5, 2016, 9:16:38 PM5/5/16
to mongodb-user

Could you please tell me how to put that information into the configuration file?

Hi,

You can specify cursorTimeoutMillis in the configuration file like so:

setParameter:
    cursorTimeoutMillis: 30000

Then run mongod pointing to the configuration file:

mongod --config /path/mongod.conf

To check the parameter value via mongo shell:

> use admin
> db.runCommand({getParameter:1, cursorTimeoutMillis:1})
{
  "cursorTimeoutMillis": 30000,
  "ok": 1 
}

The above was tested on MongoDB v3.0.11 and v3.2.6.
You may also find the following useful:

Regards,

Wan

Reply all
Reply to author
Forward
0 new messages