Update of /cvsroot/freenet/freenet/src/freenet
In directory sc8-pr-cvs1:/tmp/cvs-serv24593/freenet

Modified Files:
        OpenConnectionManager.java 
Log Message:
Fix deadlock in the changes moving sync(lru) outside of KillSurplusConnections.  No 
more deadlocks, and since we now remove from lru _before_ actually going to terminate 
the connection this still ensures that we don't kill too many

Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- OpenConnectionManager.java  26 Sep 2003 22:38:34 -0000      1.109
+++ OpenConnectionManager.java  28 Sep 2003 14:58:45 -0000      1.110
@@ -107,11 +107,9 @@
                        openConns++;
                }
         if ( maxConnections != 0 && lru.size() < maxConnections ) return;
-               synchronized(lru) {
-            /* At toad's request moving back to diong this in every thred. */
-//            lru.notifyAll();
-            KillSurplusConnections();
-        }
+        /* At toad's request moving back to diong this in every thred. */
+//        lru.notifyAll();
+        KillSurplusConnections();
     }
     
     // Removing a connection that isn't in the OCM is a 
@@ -490,54 +488,56 @@
         boolean oldestCache = false;
         boolean candidateCache = false;
         while (true) {
-            if ( maxConnections > 0 && lru.size() > maxConnections ) {
-                synchronized(closedList) {
-                    if ( !closedList.isEmpty() ) {
-                         oldest = (ConnectionHandler)closedList.removeLast();
+            synchronized(lru) {
+                if ( maxConnections > 0 && lru.size() > maxConnections ) {
+                    synchronized(closedList) {
+                        if ( !closedList.isEmpty() ) {
+                             oldest = (ConnectionHandler)closedList.removeLast();
+                        }
                     }
-                }
-                // Dump an idle connection if possible.
-                if ( oldest == null ) for (Enumeration e = lru.elements(); 
e.hasMoreElements();) {
-                    ConnectionHandler candidate = 
-                        (ConnectionHandler)e.nextElement();
-                    if (!(candidate.sending() || candidate.receiving())) {
-                        // If the oldest is open and the candidate is closed...
-                        if( !candidate.isOpen() ) {
-                            oldest = candidate;
-                            break;
-                        } else if ( oldest != null ) {
-                            //This can only happen if it closes during the run of
-                            //this loop, very unlikely but _anything_ which could
-                            //keep us from running onlyRTNodeConn is a good thing
-                            //because that involves locking hashtables, BigInteger
-                            //math and badness like that.
-                            if ( oldest != null && (!oldest.isOpen()) )
+                    // Dump an idle connection if possible.
+                    if ( oldest == null ) for (Enumeration e = lru.elements(); 
e.hasMoreElements();) {
+                        ConnectionHandler candidate = 
+                            (ConnectionHandler)e.nextElement();
+                        if (!(candidate.sending() || candidate.receiving())) {
+                            // If the oldest is open and the candidate is closed...
+                            if( !candidate.isOpen() ) {
+                                oldest = candidate;
                                 break;
-                            // If the oldest is an only-conn-to-this-RTNode and the 
-                            // candidate is not... then use the candidate
-                            if ( ( ( oldest == cached && oldestCache ) ||
-                                   ( oldestCache = onlyRTNodeConn(oldest) ) ) && 
-                                 ! ( candidateCache = onlyRTNodeConn(candidate) ) ) {
+                            } else if ( oldest != null ) {
+                                //This can only happen if it closes during the run of
+                                //this loop, very unlikely but _anything_ which could
+                                //keep us from running onlyRTNodeConn is a good thing
+                                //because that involves locking hashtables, BigInteger
+                                //math and badness like that.
+                                if ( oldest != null && (!oldest.isOpen()) )
+                                    break;
+                                // If the oldest is an only-conn-to-this-RTNode and 
the 
+                                // candidate is not... then use the candidate
+                                if ( ( ( oldest == cached && oldestCache ) ||
+                                       ( oldestCache = onlyRTNodeConn(oldest) ) ) && 
+                                     ! ( candidateCache = onlyRTNodeConn(candidate) ) 
) {
+                                    oldest = candidate;
+                                    oldestCache = candidateCache;
+                                }
+                                cached = oldest;
+                            } else {
                                 oldest = candidate;
-                                oldestCache = candidateCache;
                             }
-                            cached = oldest;
-                        } else {
-                            oldest = candidate;
                         }
                     }
-                }
-                if (oldest == null) {
-                    // Not good. This connection will most likely
-                    // be restarted, causing even more traffic :-(
-                    oldest = (ConnectionHandler)lru.pop();
+                    if (oldest == null) {
+                        // Not good. This connection will most likely
+                        // be restarted, causing even more traffic :-(
+                        oldest = (ConnectionHandler)lru.pop();
+                    } else {
+                        lru.remove(oldest);
+                    }
+
                 } else {
-                    lru.remove(oldest);
+                    //We have killed enough connections
+                    return;
                 }
-
-            } else {
-                //We have killed enough connections
-                return;
             }
             if (oldest != null) {
                 Core.diagnostics.occurrenceBinomial("connectionTimedout", 1, 0);

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to