- Fix deadlock when changing file priorities

This commit is contained in:
zzz
2012-05-22 19:26:37 +00:00
parent 0f321f1597
commit e27df771aa
2 changed files with 18 additions and 8 deletions

View File

@ -741,6 +741,7 @@ public class PeerCoordinator implements PeerListener
_log.debug("Updated piece priorities called but no priorities to set?");
return;
}
List<Piece> toCancel = new ArrayList();
synchronized(wantedPieces) {
// Add incomplete and previously unwanted pieces to the list
// Temp to avoid O(n**2)
@ -775,23 +776,31 @@ public class PeerCoordinator implements PeerListener
p.setPriority(priority);
} else {
iter.remove();
// cancel all peers
for (Peer peer : peers) {
peer.cancel(p.getId());
}
toCancel.add(p);
}
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("Updated piece priorities, now wanted: " + wantedPieces);
// if we added pieces, they will be in-order unless we shuffle
Collections.shuffle(wantedPieces, _random);
}
// update request queues, in case we added wanted pieces
// and we were previously uninterested
for (Peer peer : peers) {
peer.request();
// cancel outside of wantedPieces lock to avoid deadlocks
if (!toCancel.isEmpty()) {
// cancel all peers
for (Peer peer : peers) {
for (Piece p : toCancel) {
peer.cancel(p.getId());
}
}
}
// ditto, avoid deadlocks
// update request queues, in case we added wanted pieces
// and we were previously uninterested
for (Peer peer : peers) {
peer.request();
}
}
/**

View File

@ -2,6 +2,7 @@
* i2psnark:
- Refactor tracker map
- Prevent torrent shutdown when changing file priority to skip
- Fix deadlock when changing file priorities
* RoutingKeyModifier: Update after large clock shift
2012-05-20 zzz