Author: toad
Date: 2007-10-22 19:05:24 +0000 (Mon, 22 Oct 2007)
New Revision: 15479

Modified:
   trunk/freenet/src/freenet/node/CHKInsertSender.java
Log:
Set the status code immediately on a receive failure. But don't do a full 
finish(). Make finish() understand this if it is called afterwards.
Minor javadocs.
Trivial code moving around.
Hopefully this will prevent runaway InsertHandler's waiting in waitForStatus.

Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-10-22 19:02:25 UTC 
(rev 15478)
+++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-10-22 19:05:24 UTC 
(rev 15479)
@@ -550,17 +550,29 @@
                notifyAll();
        }

+    /**
+     * Finish the insert process. Will set status, wait for underlings to 
complete, and report success
+     * if appropriate.
+     * @param code The status code to set. 
+     * @param next The node we successfully inserted to.
+     */
     private void finish(int code, PeerNode next) {
        if(logMINOR) Logger.minor(this, "Finished: "+code+" on "+this, new 
Exception("debug"));

         synchronized(this) {   
-               if(status != NOT_FINISHED)
-                       throw new IllegalStateException("finish() called with 
"+code+" when was already "+status);
-
                if((code == ROUTE_NOT_FOUND) && !sentRequest)
                        code = ROUTE_REALLY_NOT_FOUND;

-            status = code;
+               if(status != NOT_FINISHED) {
+                       if(status == RECEIVE_FAILED) {
+                               if(code == SUCCESS)
+                                       Logger.error(this, "Request succeeded 
despite receive failed?! on "+this);
+                       }
+                       throw new IllegalStateException("finish() called with 
"+code+" when was already "+status);
+               } else {
+                status = code;
+               }
+               
                notifyAll();
                if(logMINOR) Logger.minor(this, "Set status code: 
"+getStatusString()+" on "+uid);
         }
@@ -607,6 +619,15 @@
                receiveFailed = true;
                nodesWaitingForCompletion.notifyAll();
        }
+       // Set status immediately.
+       // The code (e.g. waitForStatus()) relies on a status eventually being 
set,
+       // so we may as well set it here. The alternative is to set it in 
realRun()
+       // when we notice that receiveFailed = true.
+       synchronized(this) {
+               status = RECEIVE_FAILED;
+               notifyAll();
+       }
+       // Do not call finish(), that can only be called on the main thread and 
it will block.
     }

     /**


Reply via email to