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

MongoChangeStreamCursor tryNext() call blocks and waits indefinitely when there is a network connection loss

      Summary

      MongoChangeStreamCursor tryNext() call blocks and waits indefinitely when there is a network connection loss.

      My code looks something like this:

      MongoChangeStreamCursor<ChangeStreamDocument<Document>> cursor = collection.watch(pipeline).fullDocument(FullDocument.UPDATE_LOOKUP).cursor();
      ChangeStreamDocument<Document> changeStreamDocument = cursor.tryNext();
      {{if (changeStreamDocument != null) { }}
           // do something
      }

      The purpose of using the tryNext (instead of hasNext and next) is because of its non-blocking nature.
      But in case of a network connection loss, the tryNext call blocks the thread and waits indefinitely without throwing any exception.

      Although the MongoClient was created with these options i.e. &connectTimeoutMS=10000&serverSelectionTimeoutMS=10000, the tryNext call gets stuck even after surpassing the configured timeouts.

       

      Expected behavior
      tryNext method is expected to be a non blocking call.

      An appropriate MongoException should have been thrown immediately or as soon as the waiting time crosses the configured timeout period.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      The driver version is mongo-java-driver version 3.12.10
      But the issue could be reproduced in java driver version 3.11 also.

      The database to which I have connected is Mongo DB Atlas.

      How to Reproduce

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

      Write a simple MongoChangeStream cursor program and call to its tryNext() method and simulate a network connection loss.

      This use case can be easily tested by turning off the Wifi of the computer or the router.
      The thread dump captured using JStack is also attached.

      Additional Background

      This use case can be easily tested by turning off the Wifi of the computer or the router.
      The thread dump captured using JStack is also attached.
      The database to which I have connected is Mongo DB Atlas. The driver version is mongo-java-driver version 3.12.10

      The thread dump captured using JStack is also attached.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            ajay2589@gmail.com Ajay Mathias
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: