Author: toad
Date: 2008-03-14 18:07:48 +0000 (Fri, 14 Mar 2008)
New Revision: 18533

Modified:
   trunk/freenet/src/freenet/node/RequestSender.java
Log:
Detect very long waits, and don't wake up every 10 seconds.

Modified: trunk/freenet/src/freenet/node/RequestSender.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestSender.java   2008-03-14 17:53:44 UTC 
(rev 18532)
+++ trunk/freenet/src/freenet/node/RequestSender.java   2008-03-14 18:07:48 UTC 
(rev 18533)
@@ -914,6 +914,7 @@
      */
     public synchronized short waitUntilStatusChange(short mask) {
        if(mask == WAIT_ALL) throw new IllegalArgumentException("Cannot ignore 
all!");
+       long deadline = System.currentTimeMillis() + 300*1000;
         while(true) {
                short current = mask; // If any bits are set already, we ignore 
those states.

@@ -929,7 +930,9 @@
                if(current != mask) return current;

             try {
-                wait(10000);
+               long now = System.currentTimeMillis();
+               if(now > deadline) throw new IllegalStateException("Waited more 
than 5 minutes");
+                wait(deadline - now);
             } catch (InterruptedException e) {
                 // Ignore
             }
@@ -940,10 +943,13 @@
      * Wait until we have a terminal status code.
      */
     public synchronized void waitUntilFinished() {
+       long deadline = System.currentTimeMillis() + 300*1000;
         while(true) {
             if(status != NOT_FINISHED) return;
             try {
-                wait(10000);
+               long now = System.currentTimeMillis();
+               if(now > deadline) throw new IllegalStateException("Waited more 
than 5 minutes");
+                wait(deadline - now);
             } catch (InterruptedException e) {
                 // Ignore
             }


Reply via email to