diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2018-12-12 14:57:19 -0500 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2019-01-07 14:33:28 -0500 |
commit | 58454a7a2f5731b6810811d19816581b9e30b4ea (patch) | |
tree | a6aa553d180d4fd985ffdc030dd73182bc704374 /src | |
parent | 015c059951272735643231fa2f87640986967ca0 (diff) | |
download | mongo-58454a7a2f5731b6810811d19816581b9e30b4ea.tar.gz |
SERVER-38072 CollectionClonerTest references memory that is potentially already freed by CollectionCloner
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/collection_cloner_test.cpp | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp index c17cff0cc60..66fae8cf6d7 100644 --- a/src/mongo/db/repl/collection_cloner_test.cpp +++ b/src/mongo/db/repl/collection_cloner_test.cpp @@ -129,14 +129,7 @@ public: { stdx::unique_lock<stdx::mutex> lk(_mutex); _resuming = true; - _paused = false; - _resumedQueryCount = _queryCount; - while (_waiting) { - lk.unlock(); - _net->signalWorkAvailable(); - mongo::sleepmillis(10); - lk.lock(); - } + _resume(&lk); _resuming = false; _cond.notify_all(); } @@ -148,10 +141,15 @@ public: _cond.wait(lk, [this] { return _waiting; }); } - // Waits for the next query to run after resume() is called to complete. - void waitForResumedQuery() { + // Resumes, then waits for the next query to run after resume() is called to complete. + void resumeAndWaitForResumedQuery() { stdx::unique_lock<stdx::mutex> lk(_mutex); + _resuming = true; + _resume(&lk); + _cond.notify_all(); // This is to wake up the paused thread. _cond.wait(lk, [this] { return _resumedQueryCount != _queryCount; }); + _resuming = false; + _cond.notify_all(); // This potentially wakes up the destructor. } private: @@ -165,6 +163,18 @@ private: int _resumedQueryCount = 0; Status _failureForConnect = Status::OK(); Status _failureForQuery = Status::OK(); + + void _resume(stdx::unique_lock<stdx::mutex>* lk) { + invariant(lk->owns_lock()); + _paused = false; + _resumedQueryCount = _queryCount; + while (_waiting) { + lk->unlock(); + _net->signalWorkAvailable(); + mongo::sleepmillis(10); + lk->lock(); + } + } }; // RAII class to pause the client; since tests are very exception-heavy this prevents them @@ -185,6 +195,12 @@ public: _client = nullptr; } + void resumeAndWaitForResumedQuery() { + if (_client) + _client->resumeAndWaitForResumedQuery(); + _client = nullptr; + } + private: FailableMockDBClientConnection* _client; }; @@ -1249,8 +1265,7 @@ protected: _client->waitForPausedQuery(); ASSERT_TRUE(collectionStats.initCalled); - pauser.resume(); - _client->waitForResumedQuery(); + pauser.resumeAndWaitForResumedQuery(); } /** |