Author: toad
Date: 2008-03-11 16:18:36 +0000 (Tue, 11 Mar 2008)
New Revision: 18462

Modified:
   trunk/freenet/src/freenet/node/RequestHandler.java
Log:
Fix "Status is SUCCESS but we never started a transfer on <uid>"

Modified: trunk/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestHandler.java  2008-03-11 15:08:11 UTC 
(rev 18461)
+++ trunk/freenet/src/freenet/node/RequestHandler.java  2008-03-11 16:18:36 UTC 
(rev 18462)
@@ -86,6 +86,10 @@
        private Exception previousApplyByteCountCall;

     private void applyByteCounts() {
+       if(disconnected) {
+               Logger.normal(this, "Not applying byte counts as request source 
disconnected during receive");
+               return;
+       }
                if (appliedByteCounts) {
                        Logger.error(this, "applyByteCounts already called", 
new Exception("error"));
                        Logger.error(this, "first called here", 
previousApplyByteCountCall);
@@ -172,6 +176,8 @@
                }
        }

+       private boolean disconnected = false;
+       
        public void onCHKTransferBegins() {
                try {
                // Is a CHK.
@@ -184,6 +190,9 @@
                node.addTransferringRequestHandler(uid);
                        bt.sendAsync(node.executor);
                } catch (NotConnectedException e) {
+                       synchronized(this) {
+                               disconnected = true;
+                       }
                        Logger.normal(this, "requestor is gone, can't begin CHK 
transfer");
                }
        }
@@ -276,13 +285,13 @@
                                        sendTerminal(df);
                                }
                        } else {
-                               if(bt == null) {
+                               if(bt == null && !disconnected) {
                                        // Bug! This is impossible!
                                        Logger.error(this, "Status is SUCCESS 
but we never started a transfer on "+uid);
                                        // Obviously this node is confused, 
send a terminal reject to make sure the requestor is not waiting forever.
                            reject = DMT.createFNPRejectedOverload(uid, true);
                                sendTerminal(reject);
-                               } else {
+                               } else if(!disconnected) {
                                        waitAndFinishCHKTransferOffThread();
                                }
                        }
@@ -290,13 +299,13 @@
                case RequestSender.VERIFY_FAILURE:
                case RequestSender.GET_OFFER_VERIFY_FAILURE:
                        if(key instanceof NodeCHK) {
-                                               if(bt == null) {
+                                               if(bt == null && !disconnected) 
{
                                        // Bug! This is impossible!
                                        Logger.error(this, "Status is 
VERIFY_FAILURE but we never started a transfer on "+uid);
                                                        // Obviously this node 
is confused, send a terminal reject to make sure the requestor is not waiting 
forever.
                            reject = DMT.createFNPRejectedOverload(uid, true);
                                sendTerminal(reject);
-                               } else {
+                               } else if(!disconnected) {
                                                        //Verify fails after 
receive() is complete, so we might as well propagate it...
                                        waitAndFinishCHKTransferOffThread();
                                }
@@ -308,13 +317,13 @@
                case RequestSender.TRANSFER_FAILED:
                case RequestSender.GET_OFFER_TRANSFER_FAILED:
                        if(key instanceof NodeCHK) {
-                               if(bt == null) {
+                               if(bt == null && !disconnected) {
                                        // Bug! This is impossible!
                                        Logger.error(this, "Status is 
TRANSFER_FAILED but we never started a transfer on "+uid);
                                                        // Obviously this node 
is confused, send a terminal reject to make sure the requestor is not waiting 
forever.
                            reject = DMT.createFNPRejectedOverload(uid, true);
                                sendTerminal(reject);
-                               } else {
+                               } else if(!disconnected) {
                                        waitAndFinishCHKTransferOffThread();
                                }
                                                return;


Reply via email to