[SERVER-53434] Fix cleanup of ThreadPool in ReshardingOplogApplierTest unit test fixture Created: 18/Dec/20  Updated: 29/Oct/23  Resolved: 18/Dec/20

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Task Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Max Hirschhorn
Resolution: Fixed Votes: 0
Labels: PM-234-M2, PM-234-T-oplog-apply
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-53011 ReshardingOplogApplierTest should gra... Closed
Backwards Compatibility: Fully Compatible
Sprint: Sharding 2020-12-28
Participants:
Linked BF Score: 45
Story Points: 1

 Description   

ReshardingOplogApplierTest fixture's way of shutting down ThreadPool inexplicably throws a std::exception (EDEADLK) when attempting to reacquire _mutex after having successfully joined all of the threads. As another way of illustrating this issue, the second of the invariants in the diff below fails sometimes when ReshardingOplogApplierTest::tearDown() is called.

diff --git a/src/mongo/util/concurrency/thread_pool.cpp b/src/mongo/util/concurrency/thread_pool.cpp
index d333a82d12..b115b33033 100644
--- a/src/mongo/util/concurrency/thread_pool.cpp
+++ b/src/mongo/util/concurrency/thread_pool.cpp
@@ -307,9 +307,11 @@ void ThreadPool::Impl::_join_inlock(stdx::unique_lock<Latch>* lk) {
     _joinRetired_inlock();
     auto threadsToJoin = std::exchange(_threads, {});
     lk->unlock();
+    invariant(!lk->owns_lock());
     for (auto& t : threadsToJoin) {
         t.join();
     }
+    invariant(!lk->owns_lock());
     lk->lock();
     invariant(_state == joining);
     _setState_inlock(shutdownComplete);



 Comments   
Comment by Max Hirschhorn [ 18/Dec/20 ]

Author:

{'name': 'Max Hirschhorn', 'email': 'max.hirschhorn@mongodb.com', 'username': 'visemet'}

Message: SERVER-53434 Use local var for ThreadPool in ReshardingOplogApplierTest.

Also makes it so the ReshardingOplogApplier outlives the ThreadPool and
ThreadPoolTaskExecutor.
Branch: master
https://github.com/mongodb/mongo/commit/8cf090325609ab23d90a683fcea6b7469f91fa96

Generated at Thu Feb 08 05:30:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.