* NetDb: Fix a deadlock caused by last checkin

This commit is contained in:
zzz
2008-11-10 20:28:47 +00:00
parent 5271838a14
commit 6ce2767514
2 changed files with 12 additions and 1 deletions

View File

@@ -269,8 +269,9 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
// following are some special situations, we don't want to
// drop the peer in these cases
// yikes don't do this - stack overflow // getFloodfillPeers().size() == 0 ||
// yikes2 don't do this either - deadlock! // getKnownRouters() < MIN_REMAINING_ROUTERS ||
if (info.getNetworkId() == Router.NETWORK_ID &&
(getKnownRouters() < MIN_REMAINING_ROUTERS ||
(getKBucketSetSize() < MIN_REMAINING_ROUTERS ||
_context.router().getUptime() < DONT_FAIL_PERIOD ||
_context.commSystem().countActivePeers() <= MIN_ACTIVE_PEERS)) {
if (_log.shouldLog(Log.WARN))

View File

@@ -420,6 +420,16 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
}
}
/**
* This is fast and doesn't use synchronization,
* but it includes both routerinfos and leasesets.
* Use it to avoid deadlocks.
*/
protected int getKBucketSetSize() {
if (_kb == null) return 0;
return _kb.size();
}
public void lookupLeaseSet(Hash key, Job onFindJob, Job onFailedLookupJob, long timeoutMs) {
if (!_initialized) return;
LeaseSet ls = lookupLeaseSetLocally(key);