Author: robert
Date: 2008-01-29 16:01:21 +0000 (Tue, 29 Jan 2008)
New Revision: 17387

Modified:
   trunk/freenet/src/freenet/io/comm/MessageCore.java
Log:
eliminate double-notify race condition on dropping connection


Modified: trunk/freenet/src/freenet/io/comm/MessageCore.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageCore.java  2008-01-29 15:42:34 UTC 
(rev 17386)
+++ trunk/freenet/src/freenet/io/comm/MessageCore.java  2008-01-29 16:01:21 UTC 
(rev 17387)
@@ -306,6 +306,11 @@
                long messageDropTime = now - MAX_UNCLAIMED_FIFO_ITEM_LIFETIME;
                long messageLifeTime = 0;
                synchronized (_filters) {
+                       //Once in the list, it is up to the callback system to 
trigger the disconnection, however, we may
+                       //have disconnected between check above and locking, so 
we *must* check again.
+                       if(filter.anyConnectionsDropped()) {
+                               throw new DisconnectedException();
+                       }
                        if(logMINOR) Logger.minor(this, "Checking _unclaimed");
                        for (ListIterator i = _unclaimed.listIterator(); 
i.hasNext();) {
                                Message m = (Message) i.next();
@@ -348,14 +353,6 @@
                        filter.setMessage(ret);
                        filter.onMatched();
                        filter.clearMatched();
-               } else {
-                       // Might have disconnected between check above and 
locking _filters.
-                       if(filter.anyConnectionsDropped()) {
-                               synchronized(_filters) {
-                                       _filters.remove(filter);
-                               }
-                               throw new DisconnectedException();
-                       }
                }
        }



Reply via email to