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

      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:
            Unassigned Unassigned
            Reporter:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: