diff options
author | Romans Kasperovics <romans.kasperovics@mongodb.com> | 2022-03-15 08:55:37 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-15 09:33:32 +0000 |
commit | 80421c5b8e5ac71e16dc005fd961901884891c47 (patch) | |
tree | f10f3369dd60df12bea2c4e7060793061d4c7486 /src/mongo/s | |
parent | abe5428751586d14241f94f06261c7037690557f (diff) | |
download | mongo-80421c5b8e5ac71e16dc005fd961901884891c47.tar.gz |
SERVER-62710 Ensure that AsyncResultsMerger attempts to kill shard cursors when maxTimeMs is exceeded
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/query/async_results_merger.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/query/async_results_merger_test.cpp | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/s/query/async_results_merger.cpp b/src/mongo/s/query/async_results_merger.cpp index 56f2deff96e..363e151fbfd 100644 --- a/src/mongo/s/query/async_results_merger.cpp +++ b/src/mongo/s/query/async_results_merger.cpp @@ -852,6 +852,11 @@ void AsyncResultsMerger::_scheduleKillCursors(WithLock, OperationContext* opCtx) executor::RemoteCommandRequest request( remote.getTargetHost(), _params.getNss().db().toString(), cmdObj, opCtx); + // The 'RemoteCommandRequest' takes the remaining time from the 'opCtx' parameter. If + // the cursor was killed due to a maxTimeMs timeout, the remaining time will be 0, and + // the remote request will not be sent. To avoid this, we remove the timeout for the + // remote 'killCursor' command. + request.timeout = executor::RemoteCommandRequestBase::kNoTimeout; // Send kill request; discard callback handle, if any, or failure report, if not. _executor->scheduleRemoteCommand(request, [](auto const&) {}).getStatus().ignore(); diff --git a/src/mongo/s/query/async_results_merger_test.cpp b/src/mongo/s/query/async_results_merger_test.cpp index 6caad31478e..d089ac691c9 100644 --- a/src/mongo/s/query/async_results_merger_test.cpp +++ b/src/mongo/s/query/async_results_merger_test.cpp @@ -961,6 +961,19 @@ TEST_F(AsyncResultsMergerTest, KillCalledTwice) { killFuture2.wait(); } +TEST_F(AsyncResultsMergerTest, KillCursorCmdHasNoTimeout) { + std::vector<RemoteCursor> cursors; + cursors.push_back( + makeRemoteCursor(kTestShardIds[0], kTestShardHosts[0], CursorResponse(kTestNss, 1, {}))); + auto arm = makeARMFromExistingCursors(std::move(cursors)); + + auto* opCtx = operationContext(); + opCtx->setDeadlineAfterNowBy(Microseconds::zero(), ErrorCodes::MaxTimeMSExpired); + auto killFuture = arm->kill(opCtx); + ASSERT_EQ(executor::RemoteCommandRequestBase::kNoTimeout, getNthPendingRequest(0u).timeout); + killFuture.wait(); +} + TEST_F(AsyncResultsMergerTest, TailableBasic) { BSONObj findCmd = fromjson("{find: 'testcoll', tailable: true}"); std::vector<RemoteCursor> cursors; |