summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Shteinfeld <ben.shteinfeld@mongodb.com>2023-05-17 01:43:23 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-17 02:37:51 +0000
commitb4b4b310cd5fe22d33a749eca4e43c42c2adf76c (patch)
tree84b6fb93440f1140e6077a11d006a553fc00f155
parent31e93a577b5b1cef58424199d6ed325182db89de (diff)
downloadmongo-b4b4b310cd5fe22d33a749eca4e43c42c2adf76c.tar.gz
SERVER-77196 Prevent potential deadlock in TaskExecutorCursorTest
-rw-r--r--src/mongo/executor/task_executor_cursor_test.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/executor/task_executor_cursor_test.cpp b/src/mongo/executor/task_executor_cursor_test.cpp
index 784dedddf48..b260ea44e63 100644
--- a/src/mongo/executor/task_executor_cursor_test.cpp
+++ b/src/mongo/executor/task_executor_cursor_test.cpp
@@ -532,12 +532,17 @@ public:
// NetworkInterfaceMock.
stdx::thread t(
[this, cursorId] { scheduleSuccessfulCursorResponse("nextBatch", 3, 4, 0); });
- t.detach();
// Schedules the GetMore request and exhausts the cursor.
ASSERT_EQUALS(tec.getNext(opCtx.get()).value()["x"].Int(), 3);
ASSERT_EQUALS(tec.getNext(opCtx.get()).value()["x"].Int(), 4);
+ // Joining the thread which schedules the cursor response for the GetMore here forces the
+ // destructor of NetworkInterfaceMock::InNetworkGuard to run, which ensures that the
+ // 'NetworkInterfaceMock' stops executing as the network thread. This is required before we
+ // invoke 'hasReadyRequests()' which enters the network again.
+ t.join();
+
// Assert no GetMore is requested.
ASSERT_FALSE(hasReadyRequests());
}