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

Calling watch() for changestream will send getMore command forever

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Change Streams
    • Not Needed

      Env: mongo-java-reactivestreams v4.3.1

      Reproduce steps:

      Just Call

      com.mongodb.reactivestreams.client.internal.MongoCollectionImpl#watch(java.lang.Class<TResult>)

      to watch a collection for changestream

       

      Logs:

       

      2021-08-30 03:40:24.773 DEBUG S famuhnax [ ] Thread-18 o.m.d.p.command : Sending command '{"getMore": 4558344685700738737, "collection": "leader", "batchSize": 2147483647, "$db": "turms-config-dev", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1630294824, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "lsid": {"id": {"$binary": {"base64": "vmhYdKf2Q3ah5F7PmGpIQA==", "subType": "04"}}}}' with request id 274 to database turms-config-dev on connection [connectionId{localValue:32, serverValue:168}] to server localhost:29017
      2021-08-30 03:40:24.773 DEBUG S famuhnax [ ] Thread-15 o.m.d.p.command : Execution of command with request id 274 completed successfully in 7.26 ms on connection [connectionId{localValue:32, serverValue:168}] to server localhost:29017
      2021-08-30 03:40:27.151 DEBUG S famuhnax [ ] tter-2-thread-1 o.m.d.p.command : Sending command '{"getMore": 4558344685700738737, "collection": "leader", "batchSize": 2147483647, "$db": "turms-config-dev", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1630294825, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "lsid": {"id": {"$binary": {"base64": "vmhYdKf2Q3ah5F7PmGpIQA==", "subType": "04"}}}}' with request id 276 to database turms-config-dev on connection [connectionId{localValue:32, serverValue:168}] to server localhost:29017
      2021-08-30 03:40:27.152 DEBUG S famuhnax [ ] Thread-7 o.m.d.p.command : Execution of command with request id 276 completed successfully in 10.02 ms on connection [connectionId{localValue:32, serverValue:168}] to server localhost:29017
      2021-08-30 03:40:28.026 DEBUG S famuhnax [ ] tter-2-thread-1 o.m.d.p.command : Sending command '{"getMore": 4558344685700738737, "collection": "leader", "batchSize": 2147483647, "$db": "turms-config-dev", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1630294825, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "lsid": {"id": {"$binary": {"base64": "vmhYdKf2Q3ah5F7PmGpIQA==", "subType": "04"}}}}' with request id 282 to database turms-config-dev on connection [connectionId{localValue:32, serverValue:168}] to server localhost:29017

      As you can see from the logs, it sent getMore commands with the same cursor ID everytime ("getMore": 4558344685700738737 ), which makes it never stop.

      And I guess the bug is caused by:

      com.mongodb.internal.operation.AsyncQueryBatchCursor.CommandResultSingleResultCallback#onResult

      **, which parses the query cursor ID from the response and uses the same cursor ID to query next batch and just loop forever.

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            eurekajameschen@gmail.com James Chen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: