Author: remm
Date: Mon May 29 07:09:13 2006
New Revision: 410095

URL: http://svn.apache.org/viewvc?rev=410095&view=rev
Log:
- I had some problems when shutting down pollers which had active connections 
in them. I can't
  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.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=410095&r1=410094&r2=410095&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Mon 
May 29 07:09:13 2006
@@ -826,7 +826,7 @@
         // Close all APR memory pools and resources
         Pool.destroy(rootPool);
         rootPool = 0;
-        initialized = false ;
+        initialized = false;
     }
 
 
@@ -1132,7 +1132,7 @@
             if (comet) {
                 // FIXME: Find an appropriate timeout value, for now, "longer 
than usual"
                 // semms appropriate
-                timeout = soTimeout * 20;
+                timeout = soTimeout * 50;
             }
             serverPollset = allocatePoller(size, pool, timeout);
             if (serverPollset == 0 && size > 1024) {
@@ -1153,6 +1153,16 @@
          * Destroy the poller.
          */
         protected void destroy() {
+            // Wait for polltime before doing anything, so that the poller 
threads
+            // exit, otherwise parallel descturction of sockets which are still
+            // in the poller can cause problems
+            try {
+                synchronized (this) {
+                    this.wait(pollTime / 1000);
+                }
+            } catch (InterruptedException e) {
+                // Ignore
+            }
             // Close all sockets in the add queue
             for (int i = 0; i < addCount; i++) {
                 if (comet) {
@@ -1216,7 +1226,6 @@
                 // Loop if endpoint is paused
                 while (paused) {
                     try {
-                        // TODO: We can easly do the maintenance here
                         Thread.sleep(1000);
                     } catch (InterruptedException e) {
                         // Ignore
@@ -1293,7 +1302,7 @@
                             continue;
                         }
                     }
-                    if (soTimeout > 0 && maintainTime > 1000000L) {
+                    if (soTimeout > 0 && maintainTime > 1000000L && running) {
                         rv = Poll.maintain(serverPollset, desc, true);
                         maintainTime = 0;
                         if (rv > 0) {
@@ -1301,8 +1310,6 @@
                             for (int n = 0; n < rv; n++) {
                                 // Close socket and clear pool
                                 if (comet) {
-                                    // FIXME: should really close in case of 
timeout ?
-                                    // FIXME: maybe comet should use an 
extended timeout
                                     processSocket(desc[n], true);
                                 } else {
                                     Socket.destroy(desc[n]);
@@ -1316,8 +1323,12 @@
 
             }
 
-        }
+            synchronized (this) {
+                this.notifyAll();
+            }
 
+        }
+        
     }
 
 
@@ -1523,6 +1534,16 @@
          * Destroy the poller.
          */
         protected void destroy() {
+            // Wait for polltime before doing anything, so that the poller 
threads
+            // exit, otherwise parallel descturction of sockets which are still
+            // in the poller can cause problems
+            try {
+                synchronized (this) {
+                    this.wait(pollTime / 1000);
+                }
+            } catch (InterruptedException e) {
+                // Ignore
+            }
             // Close any socket remaining in the add queue
             for (int i = (addS.size() - 1); i >= 0; i--) {
                 SendfileData data = addS.get(i);
@@ -1725,6 +1746,10 @@
                 } catch (Throwable t) {
                     log.error(sm.getString("endpoint.poll.error"), t);
                 }
+            }
+
+            synchronized (this) {
+                this.notifyAll();
             }
 
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to