Author: j16sdiz
Date: 2009-03-16 14:27:05 +0000 (Mon, 16 Mar 2009)
New Revision: 26045

Modified:
   trunk/freenet/src/freenet/io/NetworkInterface.java
   trunk/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Quick fix FCPServer infinity loop on shutdown (NOT TESTED)

This is consider as a quick hack, not a real fix.
See bug 2638 for the real bug.

Modified: trunk/freenet/src/freenet/io/NetworkInterface.java
===================================================================
--- trunk/freenet/src/freenet/io/NetworkInterface.java  2009-03-15 15:35:03 UTC 
(rev 26044)
+++ trunk/freenet/src/freenet/io/NetworkInterface.java  2009-03-16 14:27:05 UTC 
(rev 26045)
@@ -29,10 +29,12 @@
 import java.util.List;
 import java.util.StringTokenizer;
 
+import org.tanukisoftware.wrapper.WrapperManager;
+
 import freenet.io.AddressIdentifier.AddressType;
 import freenet.support.Executor;
+import freenet.support.LogThresholdCallback;
 import freenet.support.Logger;
-import freenet.support.LogThresholdCallback;
 
 /**
  * Replacement for {...@link ServerSocket} that can handle multiple bind 
addresses
@@ -76,6 +78,8 @@
        /** The number of running acceptors. */
        private int runningAcceptors = 0;
        
+       private volatile boolean shutdown = false;
+       
        private final Executor executor;
 
        public static NetworkInterface create(int port, String bindTo, String 
allowedHosts, Executor executor, boolean ignoreUnbindableIP6) throws 
IOException {
@@ -200,7 +204,11 @@
         */
        public Socket accept() {
                synchronized (syncObject) {
-                       while (acceptedSockets.size() == 0) {
+                       while (acceptedSockets.size() == 0 ) {
+                               if (shutdown)
+                                       return null;
+                               if 
(WrapperManager.hasShutdownHookBeenTriggered())
+                                       return null;
                                if (acceptors.size() == 0) {
                                        return null;
                                }
@@ -225,6 +233,7 @@
         */
        public void close() throws IOException {
                IOException exception = null;
+               shutdown = true;
                for (Acceptor acceptor : acceptors) {
                        try {
                                acceptor.close();
@@ -232,6 +241,9 @@
                                exception = ioe1;
                        }
                }
+               synchronized (syncObject) {
+                       syncObject.notifyAll();
+               }
                if (exception != null) {
                        throw exception;
                }

Modified: trunk/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPServer.java   2009-03-15 15:35:03 UTC 
(rev 26044)
+++ trunk/freenet/src/freenet/node/fcp/FCPServer.java   2009-03-16 14:27:05 UTC 
(rev 26045)
@@ -180,6 +180,8 @@
                        } catch (Throwable t) {
                                Logger.error(this, "Caught "+t, t);
                        }
+                       if (WrapperManager.hasShutdownHookBeenTriggered())
+                               return;
                        try{
                                Thread.sleep(2000);
                        }catch (InterruptedException e) {}
@@ -189,7 +191,7 @@
        private void realRun() throws IOException {
                if(!node.isHasStarted()) return;
                // Accept a connection
-               Socket s = networkInterface.accept();
+               Socket s = networkInterface.accept();           
                FCPConnectionHandler ch = new FCPConnectionHandler(s, this);
                ch.start();
        }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to