Closed a8156268 closed 3 years ago
Currently, PeerConnectionPool.getConnection()
does not lock anything. See: https://github.com/atomashpolskiy/bt/blob/89c8fd2ff255f7354cd59e178889439da5b28716/bt-core/src/main/java/bt/net/PeerConnectionPool.java#L87
I don't see any calls to connectionLock.lock()
even in older versions. Are you using a modified version of bt that added this lock? If so, why was this locking necessary?
Yes, I did some modification. This is to reducing the connection establish count.
@Override
public PeerConnection getConnection(Peer peer, TorrentId torrentId) {
connectionLock.lock();
try {
List<PeerConnection> connectionsWithSameAddress = getConnectionsForAddress(torrentId, peer);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Checking duplicate connections for newly discovered peer: {}." +
" All connections:\n{}", peer, connectionsWithSameAddress.stream()
.map(Object::toString)
.collect(Collectors.joining("\n")));
}
for (PeerConnection connection : connectionsWithSameAddress) {
if (connection.getRemotePort() == peer.getPort()) {
return connection;
} else if (connection.getRemotePeer().getPort() == peer.getPort()) {
return connection;
}
}
return null;
} finally {
connectionLock.unlock();
}
}
It would seem that this is not a bug then - it's a request for assisting in developing a new feature.
I'm not very familiar with the code in this place, and I can see that you changed other parts of the code from the excerpted code. In general, there's a few strategies that one can use to avoid deadlocks.
Perhaps one of these strategies will help you avoid the deadlock in your feature.
Sure. Thank you.