Author: toad
Date: 2008-01-17 16:47:50 +0000 (Thu, 17 Jan 2008)
New Revision: 17097
Modified:
trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
Log:
Fix a nasty race condition causing downloads to hang.
Everyone who experienced or reported this bug, please upgrade to trunk and test
the fix!!
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2008-01-17 16:33:46 UTC (rev 17096)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2008-01-17 16:47:50 UTC (rev 17097)
@@ -248,8 +248,21 @@
synchronized(this) {
blockNums.add(i);
if(dontSchedule) return;
- if(blockNums.size() > 1) {
- if(logMINOR) Logger.minor(this, "Other blocks
queued, not scheduling: "+blockNums.size()+" : "+blockNums);
+ /**
+ * Race condition:
+ *
+ * Starter thread sees there is only one block on us,
so removes us.
+ * Another thread adds a block. We don't schedule as we
now have two blocks.
+ * Starter thread removes us.
+ * Other blocks may be added later, but we are never
rescheduled.
+ *
+ * Fixing this by only removing the SendableRequest
after we've removed the
+ * block is nontrivial with the current code.
+ * So what we do here is simply check whether we are
registered, instead of
+ * checking whether blockNums.size() > 1 as we used to.
+ */
+ if(getParentGrabArray() != null) {
+ if(logMINOR) Logger.minor(this, "Already
registered, not scheduling: "+blockNums.size()+" : "+blockNums);
return;
}
}