From b4b4b310cd5fe22d33a749eca4e43c42c2adf76c Mon Sep 17 00:00:00 2001 From: Ben Shteinfeld Date: Wed, 17 May 2023 01:43:23 +0000 Subject: SERVER-77196 Prevent potential deadlock in TaskExecutorCursorTest --- src/mongo/executor/task_executor_cursor_test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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()); } -- cgit v1.2.1