diff options
author | George Wangensteen <george.wangensteen@mongodb.com> | 2021-06-02 17:21:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-17 14:52:10 +0000 |
commit | 6e32e86f4f6340a0697706b9db7fb1d83d03b3c3 (patch) | |
tree | 38ed8f3b309746dc80eb041ea2643cc8ef9d065e /src | |
parent | 7a59105d2b769d3a86c956cc08af01d6bd59fd82 (diff) | |
download | mongo-6e32e86f4f6340a0697706b9db7fb1d83d03b3c3.tar.gz |
SERVER-57267 Fix invalid iterator use in ConnectionPool::dropConnections
(cherry picked from commit 6598a5843ed7318527c8b60bdaaacfe312bd5c51)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/executor/connection_pool.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp index 1b4c608a88d..96a8410fd9e 100644 --- a/src/mongo/executor/connection_pool.cpp +++ b/src/mongo/executor/connection_pool.cpp @@ -510,8 +510,12 @@ void ConnectionPool::dropConnections(const HostAndPort& hostAndPort) { void ConnectionPool::dropConnections(transport::Session::TagMask tags) { stdx::lock_guard lk(_mutex); - for (const auto& pair : _pools) { - auto& pool = pair.second; + // SpecificPool::triggerShutdown can cause iterator invalidation (e.g. `pool` removing itself + // from `_pools`), so we increment `it` early after grabbing a reference to the `pool` it points + // to. + for (auto it = _pools.begin(); it != _pools.end();) { + auto& pool = it->second; + ++it; if (pool->matchesTags(tags)) continue; |