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
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