diff --git a/src/common/network/RawFrameQueue.cpp b/src/common/network/RawFrameQueue.cpp index e09dd753..8cc9014b 100644 --- a/src/common/network/RawFrameQueue.cpp +++ b/src/common/network/RawFrameQueue.cpp @@ -11,6 +11,7 @@ #include "network/RawFrameQueue.h" #include "network/udp/Socket.h" #include "Log.h" +#include "Thread.h" #include "Utils.h" using namespace network; @@ -118,7 +119,8 @@ void RawFrameQueue::enqueueMessage(const uint8_t* message, uint32_t length, sock // if the queue is flushing -- don't attempt to enqueue any messages if (m_queueFlushing) { LogWarning(LOG_NET, "RawFrameQueue::enqueueMessage() -- queue is flushing, waiting to enqueue message"); - std::lock_guard lock(m_queueMutex); + while (m_queueFlushing) + Thread::sleep(2U); } uint8_t* buffer = new uint8_t[length]; diff --git a/src/fne/network/FNENetwork.cpp b/src/fne/network/FNENetwork.cpp index 527c2176..5e75a8ce 100644 --- a/src/fne/network/FNENetwork.cpp +++ b/src/fne/network/FNENetwork.cpp @@ -298,26 +298,29 @@ void FNENetwork::clock(uint32_t ms) uint32_t id = peer.first; FNEPeerConnection* connection = peer.second; if (connection != nullptr) { - if (connection->connected()) { - uint64_t dt = connection->lastPing() + ((m_host->m_pingTime * 1000) * m_host->m_maxMissedPings); - if (dt < now) { - LogInfoEx(LOG_NET, "PEER %u (%s) timed out, dt = %u, now = %u", id, connection->identity().c_str(), - dt, now); - - // set connection states for this stale connection - connection->connected(false); - connection->connectionState(NET_STAT_INVALID); - - // if the connection was an external peer or a peer link -- be noisy about a possible - // netsplit - if (connection->isExternalPeer() || connection->isPeerLink()) { - for (uint8_t i = 0U; i < 3U; i++) - LogWarning(LOG_NET, "PEER %u (%s) downstream netsplit, dt = %u, now = %u", id, connection->identity().c_str(), - dt, now); - } - - peersToRemove.push_back(id); + uint64_t dt = 0U; + if (connection->isExternalPeer() || connection->isPeerLink()) + dt = connection->lastPing() + ((m_host->m_pingTime * 1000) * (m_host->m_maxMissedPings * 2U)); + else + dt = connection->lastPing() + ((m_host->m_pingTime * 1000) * m_host->m_maxMissedPings); + + if (dt < now) { + LogInfoEx(LOG_NET, "PEER %u (%s) timed out, dt = %u, now = %u", id, connection->identity().c_str(), + dt, now); + + // set connection states for this stale connection + connection->connected(false); + connection->connectionState(NET_STAT_INVALID); + + // if the connection was an external peer or a peer link -- be noisy about a possible + // netsplit + if (connection->isExternalPeer() || connection->isPeerLink()) { + for (uint8_t i = 0U; i < 3U; i++) + LogWarning(LOG_NET, "PEER %u (%s) downstream netsplit, dt = %u, now = %u", id, connection->identity().c_str(), + dt, now); } + + peersToRemove.push_back(id); } } }