[JAVA-3675] Change Streams: KillCursor command fails with "error 143 (CursorInUse)" Created: 01/Apr/20  Updated: 27/Oct/23  Resolved: 15/Apr/20

Status: Closed
Project: Java Driver
Component/s: Change Streams, Reactive Streams
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Giger Assignee: John Stewart (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File error_143_stacktrace.txt     Text File stacktrace_for_callback_error.txt    

 Description   

Hi,

 

I've built an application using the reactive mongoDB driver for Java. The user can subscribe to updates from a collection using WebSockets, so he can be notified if new data has been inserted. However, when calling dispose() of the change stream subscription, the DB returns the following error:

command sent by the driver:

 

Sending command '{"killCursors": "data", "cursors": [6306540676380622125], "$db": "mellolam", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1585725298, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "FdRr7trb+s/1rPx4C/C/RBD6e14=", "subType": "00"}}, "keyId": 6745367209201106945}}, "lsid": {"id": {"$binary": {"base64": "whXfu4cvRWiS6kfPc0V9xQ==", "subType": "04"}}}}' with request id 67 to database xxxx on connection [connectionId{localValue:11, serverValue:329204}] to server xxxx

 

response from the server:

 

com.mongodb.MongoCommandException: Command failed with error 143 (CursorInUse): 'cursor id 6306540676380622125 is already in use' on server xxxx. The full response is {"operationTime": {"$timestamp": {"t": 1585725298, "i": 1}}, "ok": 0.0, "errmsg": "cursor id 6306540676380622125 is already in use", "code": 143, "codeName": "CursorInUse", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1585725298, "i": 1}}, "signature": {"hash": {"$binary": "FdRr7trb+s/1rPx4C/C/RBD6e14=", "$type": "00"}, "keyId": {"$numberLong": "6745367209201106945"}}}}

 

(full stack trace in the attachment)

I've implemented the same functionality using the reactive template as well as calling .watch() on the collection "manually". Both implementations produced the same error.

The implementation is as follows: A method returns a Flux of Document (or a ChangeStreamPublisher of Document) from which I then subscribe to using subscribe(). The resulting Disposable is assigned to a variable, which is then used to call dispose() if the client cancels the change stream updates.  After calling dispose() the driver sends the killCursors command and the above error is thrown. 

The error does not impact any of my logic and I haven't found a way to catch it either. The getMore operation is successfully killed on the server and no data insert events are pushed to the client any more. 

Googling for this error code returned nothing useful, so I don't have anything to go off.

I would be glad if you guys could either tell me what I'm doing wrong or if this is actually a bug in the driver (possible racing condition?).

 

Cheers and keep up the great work!

David 



 Comments   
Comment by David Giger [ 06/Apr/20 ]

Hi John,

Yes I can give that a shot. I'll let you know of the outcomes.

 

Cheers,
David

Comment by John Stewart (Inactive) [ 06/Apr/20 ]

david@akenza.com Reviewing the stack trace you provided, it aligns exactly with the stack trace for JAVA-3487. The fix for JAVA-3487 was backported to version 3.12 of the Java driver. Would it be possible for you to upgrade your Java driver to see if this issue resolves?

Comment by David Giger [ 06/Apr/20 ]

Hi Jeffrey,

Thanks for your reply!

We use a replica set hosted on MongoDB Atlas with edition/version "MongoDB 3.6.17 Enterprise".

Regarding driver version, I'm using the Maven artifact "mongodb-driver-async" with version "3.11.2". It's a dependency of "spring-boot-starter-data-mongodb-reactive" which we're using to build our Services with.

 

Cheers,
David
 
 

Comment by Jeffrey Yemin [ 06/Apr/20 ]

Hi david@akenza.com, please let us know what version of the driver and server you are using, and whether it's a replica set or sharded cluster.

Comment by David Giger [ 01/Apr/20 ]

I've added the file stacktrace_for_callback_error.txt. This is the error which is thrown by the package "org.mongodb.driver.operation" when the above MongoException is thrown.

Cheers,
David

Generated at Thu Feb 08 09:00:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.