Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3675

Change Streams: KillCursor command fails with "error 143 (CursorInUse)"

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • None

      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 

            Assignee:
            john.stewart@mongodb.com John Stewart (Inactive)
            Reporter:
            david@akenza.com David Giger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: