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

Cursors should not erase the time counted towards timeoutMS when they are being closed

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.3.0
    • Affects Version/s: None
    • Component/s: CSOT
    • None
    • Fully Compatible
    • Java Drivers
    • Not Needed

      Currently, both CommandBatchCursor and ChangeStreamBatchCursor call TimeoutContext.resetTimeoutIfPresent when are being closed. Additionally, CommandBatchCursor calls TimeoutContext.resetToDefaultMaxTime. In a situation when a cursor is used as part of an operation, this behavior resets the timeout of the whole operation, which is not correct.

      slav.babanin@mongodb.com said

      I think it could be done this way. But there is an “if” statement before killServerCursor call which has to be taken care of.

      private void killServerCursor(final MongoNamespace namespace, final ServerCursor localServerCursor,
              final Connection localConnection) {
          OperationContext operationContext = assertNotNull(getConnectionSource()).getOperationContext();
          TimeoutContext timeoutContext = operationContext.getTimeoutContext();
          timeoutContext.resetToDefaultMaxTime();
      
          TimeoutContext contextForCloseOperation = timeoutContext.copyTimeoutContext();
          contextForCloseOperation.resetTimeoutIfPresent();
          OperationContext operationContextForCloseOperation = operationContext.withTimeoutContext(contextForCloseOperation);
      
          localConnection.command(namespace.getDatabaseName(), getKillCursorsCommand(namespace, localServerCursor),
                  NoOpFieldNameValidator.INSTANCE, ReadPreference.primary(), new BsonDocumentCodec(), operationContextForCloseOperation);
      }
      

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

              Created:
              Updated:
              Resolved: