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

com.mongodb.MongoException: state should be: open when closing an change stream

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.12.1
    • Component/s: API
    • Labels:
      None
    • Environment:

      Description

      When running this small main method i get an exception

       

      public static void main(String[] args) throws InterruptedException {	
               MongoClient mongoClient = MongoClients.create("mongodb://localhost");
      	MongoDatabase db = mongoClient.getDatabase("import");
      	MongoCollection<Document> gameEntityCollection = db.getCollection("gameEnitites");
      	gameEntityCollection.watch().subscribe(new Subscriber<ChangeStreamDocument<Document>>() {		@Override
      		public void onSubscribe(Subscription s) {
      			s.request(1);
      			new Thread(() -> {
      				try {
      					Thread.sleep(100);
      					s.cancel();
      				} catch (InterruptedException e) {
      					e.printStackTrace();
      				}
      			}).start();
      		}		@Override
      		public void onNext(ChangeStreamDocument<Document> t) {
      		}		@Override
      		public void onError(Throwable t) {
      		}		@Override
      		public void onComplete() {
      		}
      	});	Thread.sleep(10000);
      }
      

      com.mongodb.MongoException: state should be: open
      	at com.mongodb.MongoException.fromThrowableNonNull(MongoException.java:79)
      	at com.mongodb.async.client.AbstractSubscription.onError(AbstractSubscription.java:135)
      	at com.mongodb.async.client.MongoIterableSubscription$2.onResult(MongoIterableSubscription.java:93)
      	at com.mongodb.async.client.MongoIterableSubscription$2.onResult(MongoIterableSubscription.java:85)
      	at com.mongodb.operation.AsyncChangeStreamBatchCursor$3.onResult(AsyncChangeStreamBatchCursor.java:133)
      	at com.mongodb.operation.AsyncChangeStreamBatchCursor$3.onResult(AsyncChangeStreamBatchCursor.java:129)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.operation.AsyncChangeStreamBatchCursor$4.onResult(AsyncChangeStreamBatchCursor.java:168)
      	at com.mongodb.operation.AsyncChangeStreamBatchCursor$4.onResult(AsyncChangeStreamBatchCursor.java:159)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.operation.AsyncQueryBatchCursor$CommandResultSingleResultCallback.onResult(AsyncQueryBatchCursor.java:331)
      	at com.mongodb.operation.AsyncQueryBatchCursor$CommandResultSingleResultCallback.onResult(AsyncQueryBatchCursor.java:310)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor$2.onResult(DefaultServer.java:242)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.internal.connection.CommandProtocolImpl$1.onResult(CommandProtocolImpl.java:83)
      	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection$1.onResult(DefaultConnectionPool.java:467)
      	at com.mongodb.internal.connection.UsageTrackingInternalConnection$2.onResult(UsageTrackingInternalConnection.java:111)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:401)
      	at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:376)
      	at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:677)
      	at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:644)
      	at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:514)
      	at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:511)
      	at com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:220)
      	at com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:203)
      	at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127)
      	at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:282)
      	at java.base/sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.completed(WindowsAsynchronousSocketChannelImpl.java:581)
      	at java.base/sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:387)
      	at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at java.base/java.lang.Thread.run(Thread.java:835)
      Caused by: java.lang.IllegalStateException: state should be: open
      	at com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)
      	at com.mongodb.internal.session.BaseClientSessionImpl.advanceOperationTime(BaseClientSessionImpl.java:107)
      	at com.mongodb.internal.session.ClientSessionContext.advanceOperationTime(ClientSessionContext.java:70)
      	at com.mongodb.internal.connection.ClusterClockAdvancingSessionContext.advanceOperationTime(ClusterClockAdvancingSessionContext.java:76)
      	at com.mongodb.internal.connection.InternalStreamConnection.updateSessionContext(InternalStreamConnection.java:537)
      	at com.mongodb.internal.connection.InternalStreamConnection.access$800(InternalStreamConnection.java:76)
      	at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:385)
      	... 15 common frames omitted
      

      it seem to occour when in `AsyncChangeStreamBatchCursor.close`
      `wrapped.close();` and `binding.release();` is called to fast one after the other. When i wait a bit with my debugger on `wrapped.close();` and then resume the exception does not occour.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: