Skip to content
Merged
24 changes: 20 additions & 4 deletions .github/scripts/clang-tidy-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import queue as queue


def run_tidy(task_queue, lock, timeout):
def run_tidy(task_queue, lock, timeout, failed_files):
watchdog = None
while True:
command = task_queue.get()
Expand All @@ -63,6 +63,14 @@ def run_tidy(task_queue, lock, timeout):
watchdog.start()

stdout, stderr = proc.communicate()
if proc.returncode != 0:
if proc.returncode < 0:
msg = "Terminated by signal %d : %s\n" % (
-proc.returncode,
" ".join(command),
)
stderr += msg.encode("utf-8")
failed_files.append(command)

with lock:
sys.stdout.write(stdout.decode("utf-8") + "\n")
Expand All @@ -82,9 +90,9 @@ def run_tidy(task_queue, lock, timeout):
task_queue.task_done()


def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
def start_workers(max_tasks, tidy_caller, arguments):
for _ in range(max_tasks):
t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
t = threading.Thread(target=tidy_caller, args=arguments)
t.daemon = True
t.start()

Expand Down Expand Up @@ -219,8 +227,10 @@ def main():
# A lock for console output.
lock = threading.Lock()

# List of files with a non-zero return code.
failed_files = []
# Run a pool of clang-tidy workers.
start_workers(max_task_count, run_tidy, task_queue, lock, args.timeout)
start_workers(max_task_count, run_tidy, (task_queue, lock, args.timeout, failed_files))

# Form the common args list.
common_clang_tidy_args = []
Expand Down Expand Up @@ -263,8 +273,12 @@ def main():

task_queue.put(command)

# Application return code
return_code = 0
# Wait for all threads to be done.
task_queue.join()
if failed_files:
return_code = 1

if yaml and args.export_fixes:
print("Writing fixes to " + args.export_fixes + " ...")
Expand All @@ -273,9 +287,11 @@ def main():
except Exception:
sys.stderr.write("Error exporting fixes.\n")
traceback.print_exc()
return_code = 1

if tmpdir:
shutil.rmtree(tmpdir)
sys.exit(return_code)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import sys

import git
import yaml
Expand Down Expand Up @@ -43,6 +44,6 @@ def index_compdb(file_contents):
"""Index the compilation database."""
result = set()
for item in file_contents:
filename = os.path.join(item["directory"], item["file"])
filename = os.path.normpath(os.path.join(item["directory"], item["file"]))
result.add(filename)
return result
18 changes: 12 additions & 6 deletions pdns/dnsdistdist/dnsdist-concurrent-connections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ void IncomingConcurrentTCPConnectionsManager::cleanup(time_t now)
const auto interval = immutable.d_tcpConnectionsRatePerClientInterval;
const auto cutOff = static_cast<time_t>(now - (interval * 60U)); // interval in minutes
for (auto& shard : s_tcpClientsConnectionMetrics) {
auto db = shard.lock();
auto& index = db->get<TimeTag>();
auto clients = shard.lock();
auto& index = clients->get<TimeTag>();
for (auto entry = index.begin(); entry != index.end();) {
if (entry->d_concurrentConnections > 0) {
/* we need to keep this around as we still have open connections */
++entry;
continue;
}
if (entry->d_lastSeen >= cutOff) {
/* this index is ordered on timestamps,
so the first valid entry we see means we are done */
Expand All @@ -177,17 +182,18 @@ void IncomingConcurrentTCPConnectionsManager::cleanup(time_t now)
void IncomingConcurrentTCPConnectionsManager::clear()
{
for (auto& shard : s_tcpClientsConnectionMetrics) {
auto db = shard.lock();
db->clear();
auto clients = shard.lock();
clients->clear();
}
s_nextCleanup.store(0);
}

size_t IncomingConcurrentTCPConnectionsManager::getNumberOfEntries()
{
size_t total = 0;
for (auto& shard : s_tcpClientsConnectionMetrics) {
auto db = shard.lock();
total += db->size();
auto clients = shard.lock();
total += clients->size();
}
return total;
}
Expand Down
31 changes: 31 additions & 0 deletions pdns/dnsdistdist/test-dnsdist-concurrent-connections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,35 @@ BOOST_FIXTURE_TEST_CASE(test_TLS_Resumed_Without_TCP_Rate_Limiting, TestFixture)
BOOST_REQUIRE(result == dnsdist::IncomingConcurrentTCPConnectionsManager::NewConnectionResult::Denied);
}

BOOST_FIXTURE_TEST_CASE(test_Live_Connections_Cleanup, TestFixture)
{
const uint64_t maxTCPConnectionsRatePerClient = 10U;
const uint64_t tcpConnectionsRatePerClientInterval = 5U;
const uint64_t maxTCPConnectionsPerClient = 1U;
const uint32_t banDuration = 10U;
initConfiguration(maxTCPConnectionsRatePerClient, tcpConnectionsRatePerClientInterval, maxTCPConnectionsPerClient, banDuration);
time_t now = time(nullptr);

const ComboAddress client{"192.0.2.1"};
/* open one connection */
auto result = dnsdist::IncomingConcurrentTCPConnectionsManager::accountNewTCPConnection(client, false, false, now);
BOOST_REQUIRE(result == dnsdist::IncomingConcurrentTCPConnectionsManager::NewConnectionResult::Allowed);

BOOST_REQUIRE_EQUAL(dnsdist::IncomingConcurrentTCPConnectionsManager::getNumberOfEntries(), 1U);

/* now we should be after interval * 60s, entries should NOT be removed because it is active */
now += 300U;
dnsdist::IncomingConcurrentTCPConnectionsManager::cleanup(now);
BOOST_REQUIRE_EQUAL(dnsdist::IncomingConcurrentTCPConnectionsManager::getNumberOfEntries(), 1U);

/* close it */
dnsdist::IncomingConcurrentTCPConnectionsManager::accountClosedTCPConnection(client);
BOOST_REQUIRE_EQUAL(dnsdist::IncomingConcurrentTCPConnectionsManager::getNumberOfEntries(), 1U);

/* now it should be removed (we need more than 60s between two cleanups) */
now += 120U;
dnsdist::IncomingConcurrentTCPConnectionsManager::cleanup(now);
BOOST_REQUIRE_EQUAL(dnsdist::IncomingConcurrentTCPConnectionsManager::getNumberOfEntries(), 0U);
}

BOOST_AUTO_TEST_SUITE_END();
Loading