r27146 - trunk/freenet/src/freenet/client/async

[email protected] Tue, 21 Apr 2009 10:01:45 +0000
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: toad
Date: 2009-04-21 10:01:44 +0000 (Tue, 21 Apr 2009)
New Revision: 27146

Modified:
   trunk/freenet/src/freenet/client/async/USKFetcher.java
Log:
Fix deadlock, move cancelling USKAttempt's out of the synchronized(this)


Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java	2009-04-21 09:56:13 UTC (rev 27145)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java	2009-04-21 10:01:44 UTC (rev 27146)
@@ -367,6 +367,7 @@
 		final long lastEd = uskManager.lookupLatestSlot(origUSK);
 		long curLatest;
 		boolean decode = false;
+		Vector<USKAttempt> killAttempts;
 		synchronized(this) {
 			runningAttempts.remove(att);
 			curLatest = att.number;
@@ -383,9 +384,10 @@
 					attemptsToStart.add(add(i));
 				}
 			}
-			cancelBefore(curLatest, context);
+			killAttempts = cancelBefore(curLatest, context);
 			fillKeysWatching(curLatest+1, context);
 		}
+		finishCancelBefore(killAttempts, context);
 		Bucket data = null;
 		if(decode) {
 			try {
@@ -441,7 +443,7 @@
 		onDNF(attempt, context);
 	}
 
-	private void cancelBefore(long curLatest, ClientContext context) {
+	private Vector<USKAttempt> cancelBefore(long curLatest, ClientContext context) {
 		Vector<USKAttempt> v = null;
 		int count = 0;
 		synchronized(this) {
@@ -455,6 +457,10 @@
 				count++;
 			}
 		}
+		return v;
+	}
+	
+	private void finishCancelBefore(Vector<USKAttempt> v, ClientContext context) {
 		if(v != null) {
 			for(int i=0;i<v.size();i++) {
 				USKAttempt att = v.get(i);
@@ -666,6 +672,7 @@
 		if(newKnownGood && !newSlotToo) return; // Only interested in slots
 		final long lastEd = uskManager.lookupLatestSlot(origUSK);
 		boolean decode = false;
+		Vector<USKAttempt> killAttempts;
 		synchronized(this) {
 			if(completed || cancelled) return;
 			decode = lastEd >= ed && data != null;
@@ -680,9 +687,10 @@
 					attemptsToStart.add(add(i));
 				}
 			}
-			cancelBefore(ed, context);
+			killAttempts = cancelBefore(ed, context);
 			fillKeysWatching(ed+1, context);
 		}
+		finishCancelBefore(killAttempts, context);
 		synchronized(this) {
 			if (decode) {
 					lastCompressionCodec = codec;