Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55532

Make ReshardingTxnCloner's ClonerOneBatchThenCanceled cancel before batch response

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 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

      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@mongodb.com Haley Connelly
            Reporter:
            haley.connelly@mongodb.com Haley Connelly
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: