aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2025-09-29 14:47:36 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2025-09-29 14:47:36 +0200
commit0e45906f27f51f89326de479b7a9cb60fc2920b8 (patch)
treeb65ec00afdce0826fe32bdf5f85a3dbb563b68de
parent87fce948967230707de283b3e7d0e833f00bfad2 (diff)
downloaddabmod-0e45906f27f51f89326de479b7a9cb60fc2920b8.tar.gz
dabmod-0e45906f27f51f89326de479b7a9cb60fc2920b8.tar.bz2
dabmod-0e45906f27f51f89326de479b7a9cb60fc2920b8.zip
common 53fdfd2: Fix race condition in TCPDataDispatcher get_statsnext
-rw-r--r--lib/Socket.cpp1
-rw-r--r--lib/Socket.h2
-rw-r--r--lib/ThreadsafeQueue.h2
3 files changed, 3 insertions, 2 deletions
diff --git a/lib/Socket.cpp b/lib/Socket.cpp
index 5c920d7..33c9c73 100644
--- a/lib/Socket.cpp
+++ b/lib/Socket.cpp
@@ -1152,6 +1152,7 @@ void TCPDataDispatcher::process()
std::vector<TCPConnection::stats_t> TCPDataDispatcher::get_stats() const
{
std::vector<TCPConnection::stats_t> s;
+ auto lock = unique_lock<mutex>(m_mutex);
for (const auto& conn : m_connections) {
s.push_back(conn.get_stats());
}
diff --git a/lib/Socket.h b/lib/Socket.h
index 29b618a..b9a40ee 100644
--- a/lib/Socket.h
+++ b/lib/Socket.h
@@ -298,7 +298,7 @@ class TCPDataDispatcher
std::thread m_listener_thread;
TCPSocket m_listener_socket;
- std::mutex m_mutex;
+ mutable std::mutex m_mutex;
std::deque<std::vector<uint8_t> > m_preroll_queue;
std::list<TCPConnection> m_connections;
};
diff --git a/lib/ThreadsafeQueue.h b/lib/ThreadsafeQueue.h
index 13bc19e..a8d2e85 100644
--- a/lib/ThreadsafeQueue.h
+++ b/lib/ThreadsafeQueue.h
@@ -31,7 +31,7 @@
#include <functional>
#include <mutex>
#include <condition_variable>
-#include <queue>
+#include <deque>
#include <utility>
#include <cassert>