[JAVA-2395] com.mongodb.MongoException$CursorNotFound: cursor not found on server Created: 24/Nov/16  Updated: 09/Feb/18  Resolved: 24/Nov/16

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 3.0.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jaipal Reddy Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello Team,
We are getting the following exception in our application.

Exception

com.mongodb.MongoCursorNotFoundException: Query failed with error code -5 and error message 'Cursor 43249415092 not found on server xx.xx.xx.xx:27017'
at com.mongodb.connection.GetMoreProtocol.receiveMessage(GetMoreProtocol.java:115)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:68)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
at com.mongodb.connection.DefaultServerConnection.getMore(DefaultServerConnection.java:194)
at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:197)
at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:93)
at com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46)
at com.mongodb.DBCursor.hasNext(DBCursor.java:152)

We are unable to find the cause since we are getting this rarely
.Sometimes Our application is unable to read from the cursor but still we are not receiving any exception.Can you help me out on this?



 Comments   
Comment by Swapnil Srivastav [ 09/Feb/18 ]

@Jaipal Reddy
Have you got any solution?

Comment by Ross Lawley [ 24/Nov/16 ]

Looks like the code is in the internal JDK java.net.SocketInputStream.socketRead0 method and no exceptions have been propagated back to the driver. There have JDK bugs reported for this issue but it seems it might be JDK dependent.

Ross

Comment by Jaipal Reddy [ 24/Nov/16 ]

Hii Ross,

Thank you for the quick response.

We had another issue.

In cases where our application is unable to read data from cursor and we hadn't received any exception,We took the thread dump and found that the thread reading data getting stuck in RUNNABLE state.

Following is the thread dump.

java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:503)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:221)
at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:102)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:416)
at com.mongodb.connection.GetMoreProtocol.receiveMessage(GetMoreProtocol.java:112)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:68)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
at com.mongodb.connection.DefaultServerConnection.getMore(DefaultServerConnection.java:194)
at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:197)
at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:93)
at com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46)
at com.mongodb.DBCursor.hasNext(DBCursor.java:152)

Why the driver is not throwing any exception?

Comment by Ross Lawley [ 24/Nov/16 ]

Hi jaipal_543,

Thanks for the ticket. Idle cursors are automatically timed out by the server, if an application calls for more results on a timed out cursor then you will get a CursorNotFound exception.

The default timeout is 10 minutes but can be configured via the cursorTimeoutMillis parameter.

You can also turn off cursor timeouts in the Java API via DBCursor#addOption and passing the QUERYOPTION_NOTIMEOUT value. However, care should be taken as after setting the noCursorTimeout option, you must either close the cursor manually with cursor.close() or by exhausting the cursor’s results.

I hope that helps,

Ross

Generated at Thu Feb 08 08:57:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.