- I had some problems when shutting down pollers which had active connections in...
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 May 2006 14:09:13 +0000 (14:09 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 May 2006 14:09:13 +0000 (14:09 +0000)
  reproduce any problem anymore, unfortunately, but I think it was because there was a poll going
  on while the sockets in the poller were being destroyed, which could then lead to these sockets
  being destroyed again. So I'm adding code to wait until the poll call is done before doing the
  poller stop.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@410095 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/AprEndpoint.java

index 82445af..20745db 100644 (file)
@@ -826,7 +826,7 @@ public class AprEndpoint {
         // Close all APR memory pools and resources\r
         Pool.destroy(rootPool);\r
         rootPool = 0;\r
-        initialized = false ;\r
+        initialized = false;\r
     }\r
 \r
 \r
@@ -1132,7 +1132,7 @@ public class AprEndpoint {
             if (comet) {\r
                 // FIXME: Find an appropriate timeout value, for now, "longer than usual"\r
                 // semms appropriate\r
-                timeout = soTimeout * 20;\r
+                timeout = soTimeout * 50;\r
             }\r
             serverPollset = allocatePoller(size, pool, timeout);\r
             if (serverPollset == 0 && size > 1024) {\r
@@ -1153,6 +1153,16 @@ public class AprEndpoint {
          * Destroy the poller.\r
          */\r
         protected void destroy() {\r
+            // Wait for polltime before doing anything, so that the poller threads\r
+            // exit, otherwise parallel descturction of sockets which are still\r
+            // in the poller can cause problems\r
+            try {\r
+                synchronized (this) {\r
+                    this.wait(pollTime / 1000);\r
+                }\r
+            } catch (InterruptedException e) {\r
+                // Ignore\r
+            }\r
             // Close all sockets in the add queue\r
             for (int i = 0; i < addCount; i++) {\r
                 if (comet) {\r
@@ -1216,7 +1226,6 @@ public class AprEndpoint {
                 // Loop if endpoint is paused\r
                 while (paused) {\r
                     try {\r
-                        // TODO: We can easly do the maintenance here\r
                         Thread.sleep(1000);\r
                     } catch (InterruptedException e) {\r
                         // Ignore\r
@@ -1293,7 +1302,7 @@ public class AprEndpoint {
                             continue;\r
                         }\r
                     }\r
-                    if (soTimeout > 0 && maintainTime > 1000000L) {\r
+                    if (soTimeout > 0 && maintainTime > 1000000L && running) {\r
                         rv = Poll.maintain(serverPollset, desc, true);\r
                         maintainTime = 0;\r
                         if (rv > 0) {\r
@@ -1301,8 +1310,6 @@ public class AprEndpoint {
                             for (int n = 0; n < rv; n++) {\r
                                 // Close socket and clear pool\r
                                 if (comet) {\r
-                                    // FIXME: should really close in case of timeout ?\r
-                                    // FIXME: maybe comet should use an extended timeout\r
                                     processSocket(desc[n], true);\r
                                 } else {\r
                                     Socket.destroy(desc[n]);\r
@@ -1316,8 +1323,12 @@ public class AprEndpoint {
 \r
             }\r
 \r
-        }\r
+            synchronized (this) {\r
+                this.notifyAll();\r
+            }\r
 \r
+        }\r
+        \r
     }\r
 \r
 \r
@@ -1523,6 +1534,16 @@ public class AprEndpoint {
          * Destroy the poller.\r
          */\r
         protected void destroy() {\r
+            // Wait for polltime before doing anything, so that the poller threads\r
+            // exit, otherwise parallel descturction of sockets which are still\r
+            // in the poller can cause problems\r
+            try {\r
+                synchronized (this) {\r
+                    this.wait(pollTime / 1000);\r
+                }\r
+            } catch (InterruptedException e) {\r
+                // Ignore\r
+            }\r
             // Close any socket remaining in the add queue\r
             for (int i = (addS.size() - 1); i >= 0; i--) {\r
                 SendfileData data = addS.get(i);\r
@@ -1727,6 +1748,10 @@ public class AprEndpoint {
                 }\r
             }\r
 \r
+            synchronized (this) {\r
+                this.notifyAll();\r
+            }\r
+\r
         }\r
 \r
     }\r