fix thread-safety issues by adding appropriate locks

This commit is contained in:
Brenton Bostick 2023-04-14 13:42:25 -04:00
parent 156e8db33a
commit ddfdf32b44
4 changed files with 20 additions and 11 deletions

View file

@ -1946,6 +1946,8 @@ void Bond::dumpInfo(int64_t now, bool force)
_lastSummaryDump = now;
float overhead = (_overheadBytes / (timeSinceLastDump / 1000.0f) / 1000.0f);
_overheadBytes = 0;
{
Mutex::Lock l(_flows_m);
log("bond: bp=%d, fi=%" PRIu64 ", mi=%d, ud=%d, dd=%d, flows=%zu, leaf=%d, overhead=%f KB/s, links=(%d/%d)",
_policy,
_failoverInterval,
@ -1957,6 +1959,7 @@ void Bond::dumpInfo(int64_t now, bool force)
overhead,
_numAliveLinks,
_numTotalLinks);
}
for (int i = 0; i < ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (_paths[i].p) {
dumpPathStatus(now, i);

View file

@ -344,6 +344,7 @@ class Bond {
*/
static bool inUse()
{
Mutex::Lock l(_bonds_m);
return ! _bondPolicyTemplates.empty() || _defaultPolicy;
}

View file

@ -123,6 +123,7 @@ void Peer::received(
}
// If same address on same interface then don't learn unless existing path isn't alive (prevents learning loop)
if (_paths[i].p->address().ipsEqual(path->address()) && _paths[i].p->localSocket() == path->localSocket()) {
Mutex::Lock _l2(_bond_m);
if (_paths[i].p->alive(now) && !_bond) {
havePath = true;
break;
@ -669,6 +670,7 @@ void Peer::recordOutgoingPacket(const SharedPtr<Path> &path, const uint64_t pack
#ifndef ZT_NO_PEER_METRICS
_outgoing_packet++;
#endif
Mutex::Lock l(_bond_m);
if (_localMultipathSupported && _bond) {
_bond->recordOutgoingPacket(path, packetId, payloadLength, verb, flowId, now);
}
@ -679,6 +681,7 @@ void Peer::recordIncomingInvalidPacket(const SharedPtr<Path>& path)
#ifndef ZT_NO_PEER_METRICS
_packet_errors++;
#endif
Mutex::Lock l(_bond_m);
if (_localMultipathSupported && _bond) {
_bond->recordIncomingInvalidPacket(path);
}
@ -687,6 +690,7 @@ void Peer::recordIncomingInvalidPacket(const SharedPtr<Path>& path)
void Peer::recordIncomingPacket(const SharedPtr<Path> &path, const uint64_t packetId,
uint16_t payloadLength, const Packet::Verb verb, const int32_t flowId, int64_t now)
{
Mutex::Lock l(_bond_m);
if (_localMultipathSupported && _bond) {
_bond->recordIncomingPacket(path, packetId, payloadLength, verb, flowId, now);
}

View file

@ -521,6 +521,7 @@ public:
* @return The bonding policy used to reach this peer
*/
SharedPtr<Bond> bond() {
Mutex::Lock l(_bond_m);
return _bond;
}