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

If Subscriber.onNext throws an exception, then BatchCursor.close is not called, AsyncQueryBatchCursor does not kill the server cursor

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Reactive Streams
    • Labels:
      None

      ChangeStreamPublisher<Document> changeStreamPublisher = mongoCollection.watch();
      changeStreamPublisher.subscribe(new Subscriber<ChangeStreamDocument<Document>>() {
          private Subscription s;
      
          @Override
          public void onSubscribe(final Subscription s) {
              this.s = s;
              s.request(1);
          }
      
          @Override
          public void onNext(final ChangeStreamDocument<Document> doc) {
              if (true) throw new OutOfMemoryError();//or RuntimeException
          }
          ...
      });
      

      Note that AsyncQueryBatchCursor always releases the connection before calling Subscriber.onNext. If Subscriber.onNext throws an exception before/after calling Subscription.request, then

      • The Reactor logs the exception in some cases (e.g., OOM is logged, RuntimeException is not), neither Subscriber.onNext nor Subscriber.onError are called (this is fine according to Subscriber rule 13).
      • BatchCursor.close is not called - this is a problem.
      • The server cursor is not killed by AsyncQueryBatchCursor - this is a problem.

      The problem was initially discovered as JAVA-3907 scenario 3).

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: