From c68b99dc61b7b36cac312ede1b7327293b22c813 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Mon, 3 Mar 2025 10:16:29 -0500 Subject: [PATCH] silence frame queue read errors after 5 consecutive errors (this is to prevent log spam); --- src/common/network/FrameQueue.cpp | 10 +++++++++- src/common/network/RawFrameQueue.cpp | 11 ++++++++++- src/common/network/RawFrameQueue.h | 3 +++ src/host/network/Network.cpp | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/common/network/FrameQueue.cpp b/src/common/network/FrameQueue.cpp index 3c855629..170f7434 100644 --- a/src/common/network/FrameQueue.cpp +++ b/src/common/network/FrameQueue.cpp @@ -57,7 +57,13 @@ UInt8Array FrameQueue::read(int& messageLength, sockaddr_storage& address, uint3 ::memset(buffer, 0x00U, DATA_PACKET_LENGTH); int length = m_socket->read(buffer, DATA_PACKET_LENGTH, address, addrLen); if (length < 0) { - LogError(LOG_NET, "Failed reading data from the network"); + if (m_failedReadCnt <= MAX_FAILED_READ_CNT_LOGGING) + LogError(LOG_NET, "Failed reading data from the network, failedCnt = %u", m_failedReadCnt); + else { + if (m_failedReadCnt == MAX_FAILED_READ_CNT_LOGGING + 1U) + LogError(LOG_NET, "Failed reading data from the network -- exceeded 5 read errors, probable connection issue, silencing further errors"); + } + m_failedReadCnt++; return nullptr; } @@ -65,6 +71,8 @@ UInt8Array FrameQueue::read(int& messageLength, sockaddr_storage& address, uint3 if (m_debug) Utils::dump(1U, "Network Packet", buffer, length); + m_failedReadCnt = 0U; + if (length < RTP_HEADER_LENGTH_BYTES + RTP_EXTENSION_HEADER_LENGTH_BYTES) { LogError(LOG_NET, "FrameQueue::read(), message received from network is malformed! %u bytes != %u bytes", RTP_HEADER_LENGTH_BYTES + RTP_EXTENSION_HEADER_LENGTH_BYTES, length); diff --git a/src/common/network/RawFrameQueue.cpp b/src/common/network/RawFrameQueue.cpp index e6e7ea0f..1f85d1d8 100644 --- a/src/common/network/RawFrameQueue.cpp +++ b/src/common/network/RawFrameQueue.cpp @@ -33,6 +33,7 @@ std::mutex RawFrameQueue::m_flushMutex; RawFrameQueue::RawFrameQueue(udp::Socket* socket, bool debug) : m_socket(socket), m_buffers(), + m_failedReadCnt(0U), m_debug(debug) { /* stub */ @@ -56,7 +57,13 @@ UInt8Array RawFrameQueue::read(int& messageLength, sockaddr_storage& address, ui ::memset(buffer, 0x00U, DATA_PACKET_LENGTH); int length = m_socket->read(buffer, DATA_PACKET_LENGTH, address, addrLen); if (length < 0) { - LogError(LOG_NET, "Failed reading data from the network"); + if (m_failedReadCnt <= MAX_FAILED_READ_CNT_LOGGING) + LogError(LOG_NET, "Failed reading data from the network, failedCnt = %u", m_failedReadCnt); + else { + if (m_failedReadCnt == MAX_FAILED_READ_CNT_LOGGING + 1U) + LogError(LOG_NET, "Failed reading data from the network -- exceeded 5 read errors, probable connection issue, silencing further errors"); + } + m_failedReadCnt++; return nullptr; } @@ -64,6 +71,8 @@ UInt8Array RawFrameQueue::read(int& messageLength, sockaddr_storage& address, ui if (m_debug) Utils::dump(1U, "Network Packet", buffer, length); + m_failedReadCnt = 0U; + // copy message messageLength = length; UInt8Array message = std::unique_ptr(new uint8_t[length]); diff --git a/src/common/network/RawFrameQueue.h b/src/common/network/RawFrameQueue.h index 2393c986..f0d6671f 100644 --- a/src/common/network/RawFrameQueue.h +++ b/src/common/network/RawFrameQueue.h @@ -29,6 +29,7 @@ namespace network // --------------------------------------------------------------------------- const uint32_t DATA_PACKET_LENGTH = 8192U; + const uint8_t MAX_FAILED_READ_CNT_LOGGING = 5U; // --------------------------------------------------------------------------- // Class Declaration @@ -96,6 +97,8 @@ namespace network static std::mutex m_flushMutex; udp::BufferVector m_buffers; + uint32_t m_failedReadCnt; + bool m_debug; private: diff --git a/src/host/network/Network.cpp b/src/host/network/Network.cpp index 0a5699bb..2f84900b 100644 --- a/src/host/network/Network.cpp +++ b/src/host/network/Network.cpp @@ -669,7 +669,7 @@ bool Network::open() LogMessage(LOG_NET, "PEER %u opening network", m_peerId); if (udp::Socket::lookup(m_address, m_port, m_addr, m_addrLen) != 0) { - LogMessage(LOG_NET, "Could not lookup the address of the master"); + LogMessage(LOG_NET, "!!! Could not lookup the address of the master!"); return false; }