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: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: CSOT
    • None
    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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: