Author: markt
Date: Tue Aug 16 10:17:33 2011
New Revision: 1158183

URL: http://svn.apache.org/viewvc?rev=1158183&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51515
Prevent immediate socket close when comet is used over HTTPS
  

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1158183&r1=1158182&r2=1158183&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Aug 16 10:17:33 2011
@@ -96,10 +96,3 @@ PATCHES PROPOSED TO BACKPORT:
         I wonder whether ConcurrentHashMap.DEFAULT_CONCURRENCY_LEVEL which is 
16 is enough.
       - getStuckThreadIds() returns a list of ids. It might be useful to
         have a similar method that returns Thread.getName() names.
-
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51515
-  Prevent immediate socket close when comet is used over HTTPS
-  http://people.apache.org/~markt/patches/2011-07-22-bug51515-tc6.patch
-  (note: The only change to NioEndpoint is adding a sync)
-  +1: markt, jfclere, kkolinko
-  -1:

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?rev=1158183&r1=1158182&r2=1158183&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java 
Tue Aug 16 10:17:33 2011
@@ -746,13 +746,7 @@ public class Http11NioProtocol implement
                     // In the middle of processing a request/response. Keep the
                     // socket associated with the processor.
                     connections.put(socket, processor);
-
-                    if (processor.comet) {
-                        NioEndpoint.KeyAttachment att = 
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
-                        socket.getPoller().add(socket,att.getCometOps());
-                    } else {
-                        socket.getPoller().add(socket);
-                    }
+                    socket.getPoller().add(socket);
                 } else if (state == SocketState.OPEN) {
                     // In keep-alive but between requests. OK to recycle
                     // processor. Continue to poll for the next request.

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1158183&r1=1158182&r2=1158183&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue 
Aug 16 10:17:33 2011
@@ -2251,83 +2251,85 @@ public class NioEndpoint {
         }
          
         public void run() {
-            NioEndpoint.this.activeSocketProcessors.addAndGet(1);
-            SelectionKey key = null;
-            try {
-                key = 
socket.getIOChannel().keyFor(socket.getPoller().getSelector());
-                int handshake = -1;
-                
+            synchronized (socket) {
+                NioEndpoint.this.activeSocketProcessors.addAndGet(1);
+                SelectionKey key = null;
                 try {
-                    if (key!=null) handshake = 
socket.handshake(key.isReadable(), key.isWritable());
-                }catch ( IOException x ) {
-                    handshake = -1;
-                    if ( log.isDebugEnabled() ) log.debug("Error during SSL 
handshake",x);
-                }catch ( CancelledKeyException ckx ) {
-                    handshake = -1;
-                }
-                if ( handshake == 0 ) {
-                    // Process the request from this socket
-                    boolean closed = 
(status==null)?(handler.process(socket)==Handler.SocketState.CLOSED) :
-                        
(handler.event(socket,status)==Handler.SocketState.CLOSED);
-
-                    if (closed) {
-                        // Close socket and pool
-                        try {
-                            KeyAttachment ka = null;
-                            if (key!=null) {
-                                ka = (KeyAttachment) key.attachment();
-                                if (ka!=null) ka.setComet(false);
-                                socket.getPoller().cancelledKey(key, 
SocketStatus.ERROR, false);
+                    key = 
socket.getIOChannel().keyFor(socket.getPoller().getSelector());
+                    int handshake = -1;
+                    
+                    try {
+                        if (key!=null) handshake = 
socket.handshake(key.isReadable(), key.isWritable());
+                    }catch ( IOException x ) {
+                        handshake = -1;
+                        if ( log.isDebugEnabled() ) log.debug("Error during 
SSL handshake",x);
+                    }catch ( CancelledKeyException ckx ) {
+                        handshake = -1;
+                    }
+                    if ( handshake == 0 ) {
+                        // Process the request from this socket
+                        boolean closed = 
(status==null)?(handler.process(socket)==Handler.SocketState.CLOSED) :
+                            
(handler.event(socket,status)==Handler.SocketState.CLOSED);
+    
+                        if (closed) {
+                            // Close socket and pool
+                            try {
+                                KeyAttachment ka = null;
+                                if (key!=null) {
+                                    ka = (KeyAttachment) key.attachment();
+                                    if (ka!=null) ka.setComet(false);
+                                    socket.getPoller().cancelledKey(key, 
SocketStatus.ERROR, false);
+                                }
+                                if (socket!=null) nioChannels.offer(socket);
+                                socket = null;
+                                if ( ka!=null ) keyCache.offer(ka);
+                                ka = null;
+                            }catch ( Exception x ) {
+                                log.error("",x);
                             }
-                            if (socket!=null) nioChannels.offer(socket);
-                            socket = null;
-                            if ( ka!=null ) keyCache.offer(ka);
-                            ka = null;
-                        }catch ( Exception x ) {
-                            log.error("",x);
+                        } 
+                    } else if (handshake == -1 ) {
+                        KeyAttachment ka = null;
+                        if (key!=null) {
+                            ka = (KeyAttachment) key.attachment();
+                            socket.getPoller().cancelledKey(key, 
SocketStatus.DISCONNECT, false);
                         }
-                    } 
-                } else if (handshake == -1 ) {
-                    KeyAttachment ka = null;
-                    if (key!=null) {
-                        ka = (KeyAttachment) key.attachment();
-                        socket.getPoller().cancelledKey(key, 
SocketStatus.DISCONNECT, false);
+                        if (socket!=null) nioChannels.offer(socket);
+                        socket = null;
+                        if ( ka!=null ) keyCache.offer(ka);
+                        ka = null;
+                    } else {
+                        final SelectionKey fk = key;
+                        final int intops = handshake;
+                        final KeyAttachment ka = 
(KeyAttachment)fk.attachment();
+                        ka.getPoller().add(socket,intops);
                     }
-                    if (socket!=null) nioChannels.offer(socket);
-                    socket = null;
-                    if ( ka!=null ) keyCache.offer(ka);
-                    ka = null;
-                } else {
-                    final SelectionKey fk = key;
-                    final int intops = handshake;
-                    final KeyAttachment ka = (KeyAttachment)fk.attachment();
-                    ka.getPoller().add(socket,intops);
-                }
-            }catch(CancelledKeyException cx) {
-                socket.getPoller().cancelledKey(key,null,false);
-            } catch (OutOfMemoryError oom) {
-                try {
-                    oomParachuteData = null;
-                    
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
-                    releaseCaches();
-                    log.error("", oom);
-                }catch ( Throwable oomt ) {
+                }catch(CancelledKeyException cx) {
+                    socket.getPoller().cancelledKey(key,null,false);
+                } catch (OutOfMemoryError oom) {
                     try {
-                        System.err.println(oomParachuteMsg);
-                        oomt.printStackTrace();
-                    }catch (Throwable letsHopeWeDontGetHere){}
+                        oomParachuteData = null;
+                        
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
+                        releaseCaches();
+                        log.error("", oom);
+                    }catch ( Throwable oomt ) {
+                        try {
+                            System.err.println(oomParachuteMsg);
+                            oomt.printStackTrace();
+                        }catch (Throwable letsHopeWeDontGetHere){}
+                    }
+                }catch ( Throwable t ) {
+                    log.error("",t);
+                    
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
+                } finally {
+                    socket = null;
+                    status = null;
+                    //return to cache
+                    processorCache.offer(this);
+                    NioEndpoint.this.activeSocketProcessors.addAndGet(-1);
                 }
-            }catch ( Throwable t ) {
-                log.error("",t);
-                socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
-            } finally {
-                socket = null;
-                status = null;
-                //return to cache
-                processorCache.offer(this);
-                NioEndpoint.this.activeSocketProcessors.addAndGet(-1);         
   }
+            }
         }
-
     }
     
     // ---------------------------------------------- TaskQueue Inner Class

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1158183&r1=1158182&r2=1158183&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Aug 16 10:17:33 2011
@@ -230,6 +230,10 @@
         Prevent NPEs when a socket is closed in non-error conditions after
         sendfile processing when using the HTTP NIO connector. (markt) 
       </fix>
+      <fix>
+        <bug>51515</bug>: Prevent immediate socket close when comet is used 
over
+        HTTPS. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to