From 3d313832e1363aaacb7db1546fcdbd9f7ffd148e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 30 Apr 2021 15:48:58 +0200 Subject: [PATCH] dnsdist: Convert the TCP client counts map to LockGuarded --- pdns/dnsdist-tcp.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index cf253caf7c..0a7da95372 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -55,8 +55,7 @@ Let's start naively. */ -static std::mutex s_tcpClientsCountMutex; -static std::map s_tcpClientsCount; +static LockGuarded> s_tcpClientsCount; size_t g_maxTCPQueriesPerConn{0}; size_t g_maxTCPConnectionDuration{0}; @@ -203,10 +202,10 @@ size_t DownstreamConnectionsManager::s_maxCachedConnectionsPerDownstream{10}; static void decrementTCPClientCount(const ComboAddress& client) { if (g_maxTCPConnectionsPerClient) { - std::lock_guard lock(s_tcpClientsCountMutex); - s_tcpClientsCount.at(client)--; - if (s_tcpClientsCount[client] == 0) { - s_tcpClientsCount.erase(client); + auto tcpClientsCount = s_tcpClientsCount.lock(); + tcpClientsCount->at(client)--; + if (tcpClientsCount->at(client) == 0) { + tcpClientsCount->erase(client); } } } @@ -1282,13 +1281,13 @@ void tcpAcceptorThread(ClientState* cs) } if (g_maxTCPConnectionsPerClient) { - std::lock_guard lock(s_tcpClientsCountMutex); + auto tcpClientsCount = s_tcpClientsCount.lock(); - if (s_tcpClientsCount[remote] >= g_maxTCPConnectionsPerClient) { + if ((*tcpClientsCount)[remote] >= g_maxTCPConnectionsPerClient) { vinfolog("Dropping TCP connection from %s because we have too many from this client already", remote.toStringWithPort()); continue; } - s_tcpClientsCount[remote]++; + (*tcpClientsCount)[remote]++; tcpClientCountIncremented = true; } -- 2.47.2