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

XMLWordPrintableJSON

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

      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 Kavalenka
              Reporter:
              Valentin Kavalenka
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: