• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 18554180908

16 Oct 2025 07:48AM UTC coverage: 65.813% (-0.01%) from 65.825%
18554180908

Pull #16271

github

web-flow
Merge 4dcb65194 into feeb24672
Pull Request #16271: auth-5.0.x: Backport 15267: Fix the build-packages workflow

42046 of 92452 branches covered (45.48%)

Branch coverage included in aggregate %.

127953 of 165855 relevant lines covered (77.15%)

5719692.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.79
/pdns/recursordist/rec-tcpout.cc
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22

23
#include "rec-tcpout.hh"
24

25
// This line from /usr/include/openssl/ssl2.h: # define CERT char
26
// throws dnsrecords.hh off the rails.
27
#undef CERT
28

29
#include "syncres.hh"
30

31
timeval TCPOutConnectionManager::s_maxIdleTime;
32
size_t TCPOutConnectionManager::s_maxQueries;
33
size_t TCPOutConnectionManager::s_maxIdlePerAuth;
34
size_t TCPOutConnectionManager::s_maxIdlePerThread;
35

36
void TCPOutConnectionManager::cleanup(const struct timeval& now)
37
{
782✔
38
  if (s_maxIdleTime.tv_sec == 0 && s_maxIdleTime.tv_usec == 0) {
782!
39
    // no maximum idle time
40
    return;
×
41
  }
×
42

43
  for (auto it = d_idle_connections.begin(); it != d_idle_connections.end();) {
782!
44
    timeval idle = now - it->second.d_last_used;
×
45
    if (s_maxIdleTime < idle) {
×
46
      it = d_idle_connections.erase(it);
×
47
    }
×
48
    else {
×
49
      ++it;
×
50
    }
×
51
  }
×
52
}
782✔
53

54
void TCPOutConnectionManager::store(const struct timeval& now, const ComboAddress& ip, Connection&& connection)
55
{
13✔
56
  ++connection.d_numqueries;
13✔
57
  if (s_maxQueries > 0 && connection.d_numqueries >= s_maxQueries) {
13!
58
    return;
×
59
  }
×
60

61
  if (d_idle_connections.size() >= s_maxIdlePerThread || d_idle_connections.count(ip) >= s_maxIdlePerAuth) {
13!
62
    cleanup(now);
×
63
  }
×
64

65
  if (d_idle_connections.size() >= s_maxIdlePerThread) {
13!
66
    return;
×
67
  }
×
68
  if (d_idle_connections.count(ip) >= s_maxIdlePerAuth) {
13!
69
    return;
×
70
  }
×
71

72
  gettimeofday(&connection.d_last_used, nullptr);
13✔
73
  d_idle_connections.emplace(ip, std::move(connection));
13✔
74
}
13✔
75

76
TCPOutConnectionManager::Connection TCPOutConnectionManager::get(const ComboAddress& ip)
77
{
15✔
78
  if (d_idle_connections.count(ip) > 0) {
15✔
79
    auto h = d_idle_connections.extract(ip);
4✔
80
    return h.mapped();
4✔
81
  }
4✔
82
  return Connection{};
11✔
83
}
15✔
84

85
uint64_t getCurrentIdleTCPConnections()
86
{
179✔
87
  return broadcastAccFunction<uint64_t>([] { return t_tcp_manager.getSize(); });
932✔
88
}
179✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc