Possible deadlock fix.

This commit is contained in:
Adam Ierymenko 2017-08-07 14:13:08 -07:00
parent e4823381c6
commit 7e6598e9ca

View File

@ -250,20 +250,23 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,uint64_t now,volatile uint
_lastPingCheck = now; _lastPingCheck = now;
// Get networks that need config without leaving mutex locked // Get networks that need config without leaving mutex locked
std::vector< SharedPtr<Network> > needConfig;
{ {
Mutex::Lock _l(_networks_m); std::vector< std::pair< SharedPtr<Network>,bool > > nwl;
Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(_networks); {
uint64_t *k = (uint64_t *)0; Mutex::Lock _l(_networks_m);
SharedPtr<Network> *v = (SharedPtr<Network> *)0; nwl.reserve(_networks.size()+1);
while (i.next(k,v)) { Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(_networks);
if (((now - (*v)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!(*v)->hasConfig())) uint64_t *k = (uint64_t *)0;
needConfig.push_back(*v); SharedPtr<Network> *v = (SharedPtr<Network> *)0;
(*v)->sendUpdatesToMembers(tptr); while (i.next(k,v))
nwl.push_back( std::pair< SharedPtr<Network>,bool >(*v,(((now - (*v)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!(*v)->hasConfig()))) );
}
for(std::vector< std::pair< SharedPtr<Network>,bool > >::const_iterator n(nwl.begin());n!=nwl.end();++n) {
if (n->second)
n->first->requestConfiguration(tptr);
n->first->sendUpdatesToMembers(tptr);
} }
} }
for(std::vector< SharedPtr<Network> >::const_iterator n(needConfig.begin());n!=needConfig.end();++n)
(*n)->requestConfiguration(tptr);
// Do pings and keepalives // Do pings and keepalives
Hashtable< Address,std::vector<InetAddress> > upstreamsToContact; Hashtable< Address,std::vector<InetAddress> > upstreamsToContact;