@@ -55,19 +55,8 @@ bool ConnectionPool::close() {
5555 return false ;
5656 }
5757
58- std::vector<ClientConnectionPtr> connectionsToClose;
59- // ClientConnection::close() will remove the connection from the pool, which is not allowed when iterating
60- // over a map, so we store the connections to close in a vector first and don't iterate the pool when
61- // closing the connections.
62- std::unique_lock<std::recursive_mutex> lock (mutex_);
63- connectionsToClose.reserve (pool_.size ());
64- for (auto && kv : pool_) {
65- connectionsToClose.emplace_back (kv.second );
66- }
67- pool_.clear ();
68- lock.unlock ();
69-
70- for (auto && cnx : connectionsToClose) {
58+ for (auto && kv : releaseConnections ()) {
59+ auto & cnx = kv.second ;
7160 if (cnx) {
7261 // Close with a fatal error to not let client retry
7362 auto & future = cnx->close (ResultAlreadyClosed);
@@ -96,14 +85,9 @@ bool ConnectionPool::close() {
9685}
9786
9887void ConnectionPool::closeAllConnectionsForNewCluster () {
99- std::unique_lock<std::recursive_mutex> lock (mutex_);
100- for (auto cnxIt = pool_.begin (); cnxIt != pool_.end (); cnxIt++) {
101- auto & cnx = cnxIt->second ;
102- if (cnx) {
103- cnx->close (ResultDisconnected, true );
104- }
88+ for (auto && kv : releaseConnections ()) {
89+ kv.second ->close (ResultDisconnected, true );
10590 }
106- pool_.clear ();
10791}
10892
10993static const std::string getKey (const std::string& logicalAddress, const std::string& physicalAddress,
0 commit comments