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

MongoException: next() called after the cursor was closed

    • Type: Icon: Question Question
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.9.0
    • Affects Version/s: 4.8.0
    • Component/s: None
    • Labels:
      None

      Summary

      When I run several async requests against Mongo and then cancel after receiving the first result, I get the error:

      ERROR reactor.core.publisher.Operators - Operator called default onErrorDropped
      reactor.core.Exceptions$ErrorCallbackNotImplemented: com.mongodb.MongoException: next() called after the cursor was closed.
      Caused by: com.mongodb.MongoException: next() called after the cursor was closed.
      

      I am using Rx Java .firstElement() in order to cancel unwanted requests.

       
      This is using...
      driver version: 4.8.0
      Mongo version: 6
      Topology: replica set

      How to Reproduce

      I cannot provide exact steps to reproduce the database but the query below matches a couple of entries in the database which are indexed. This code triggers the exception every time. 

       

      Flowable.range(1, 200)
          .flatMapMaybe(
              iter ->
                  Flowable.fromIterable(Vector.of(mainCollection, mainCollection))
                      .map(
                          dataBaseName ->
                              mongoClient.getDatabase(dataBaseName).getCollection(collectionName))
                      .flatMap(collection -> Flowable.fromPublisher(collection.find()))
                      .firstElement())
          .collect(Vector.collector())
          .blockingGet();
      

        
       

      Additional Background

      It appears to be the double nesting of Flowables that helps trigger this bug. With a very large flat list of queries it doesn't trigger.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            sam@unlikely.ai Sam Weston
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: