Make ReshardingTxnCloner's ClonerOneBatchThenCanceled cancel before batch response

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: Major - P3
    • 4.9.0-rc1, 5.0.0-rc0
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Fully Compatible
    • v4.9
    • Sharding 2021-04-05
    • 154
    • 1
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Before returning the batch response in ClonerOneBatchThenCanceled, the test should cancel the cancelToken to prevent the cloner from potentially making it another round before it gets cancelled. This is done in other test cases for the ReshardingTxnCloner
      Note - the token should be canceled only once the request is sent to make sure the first batch doesn't get skipped entirely.

      Motivation:
      The test can hang if the token gets cancelled after the first batch is processed and already awaiting a new response. 

      It can be reproduced as follows 

      TEST_F(ReshardingTxnClonerTest, ClonerOneBatchThenCanceled) {
          const auto txns = makeSortedTxns(4);
          auto executor = makeTaskExecutorForCloner();
          ReshardingTxnCloner cloner(kTwoSourceIdList[1], Timestamp::max());
          auto opCtxToken = operationContext()->getCancellationToken();
          auto cancelSource = CancellationSource(opCtxToken);
          auto future = runCloner(cloner, executor, cancelSource.token());
       
          onCommandReturnTxnBatch(std::vector<BSONObj>(txns.begin(), txns.begin() + 2),
                                  CursorId{123},
                                  true /* isFirstBatch */);
          sleepsecs(2); // <---------------------- added for repro
          cancelSource.cancel();
       
          auto status = future.getNoThrow();
          ASSERT_EQ(status.code(), ErrorCodes::CallbackCanceled);
      }
      

            Assignee:
            Haley Connelly
            Reporter:
            Haley Connelly
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: