Author: markt
Date: Tue Mar 19 22:51:15 2013
New Revision: 1458559

URL: http://svn.apache.org/r1458559
Log:
As highlighted by the Autobahn tests, a protocol error needs to force an 
immediate close. The server can't wait for a echoed close frame from a 
connection that is in an unknown state.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
    tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
    tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1458559&r1=1458558&r2=1458559&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Tue Mar 19 
22:51:15 2013
@@ -345,8 +345,10 @@ public class WsSession implements Sessio
 
     /**
      * Called when a close message is received. Should only ever happen once.
+     * Also called after a protocol error when the ProtocolHandler needs to
+     * force the closing of the connection.
      */
-    void onClose(CloseReason closeReason) {
+    public void onClose(CloseReason closeReason) {
 
         boolean sendCloseMessage = false;
 

Modified: 
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1458559&r1=1458558&r2=1458559&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties 
(original)
+++ 
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties 
Tue Mar 19 22:51:15 2013
@@ -24,6 +24,4 @@ serverContainer.servletContextMissing=No
 
 uriTemplate.noMatch=The input template [{0}] generated the pattern [{1}] which 
did not match the supplied pathInfo [{2}]
 
-wsProtocolHandler.closeFailed=Failed to close the WebSocket connection cleanly
-
 wsRemoteEndpointServer.closeFailed=Failed to close the ServletOutputStream 
connection cleanly
\ No newline at end of file

Modified: 
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java?rev=1458559&r1=1458558&r2=1458559&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java 
Tue Mar 19 22:51:15 2013
@@ -32,9 +32,6 @@ import javax.websocket.DeploymentExcepti
 import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfig;
 
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.websocket.WsIOException;
 import org.apache.tomcat.websocket.WsSession;
 
@@ -43,11 +40,6 @@ import org.apache.tomcat.websocket.WsSes
  */
 public class WsProtocolHandler implements HttpUpgradeHandler {
 
-    private static final StringManager sm =
-            StringManager.getManager(Constants.PACKAGE_NAME);
-    private static final Log log =
-            LogFactory.getLog(WsProtocolHandler.class);
-
     private final Endpoint ep;
     private final EndpointConfig endpointConfig;
     private final ClassLoader applicationClassLoader;
@@ -132,13 +124,15 @@ public class WsProtocolHandler implement
 
 
     private void close(CloseReason cr) {
-        try {
-            wsSession.close(cr);
-        } catch (IOException e) {
-            if (log.isInfoEnabled()) {
-                log.info(sm.getString("wsProtocolHandler.closeFailed"), e);
-            }
-        }
+        /*
+         * Any call to this method is a result of a problem reading from the
+         * client. At this point that state of the connection is unknown.
+         * Attempt to send a close frame to the client and then close the 
socket
+         * immediately. There is no point in waiting for a close frame from the
+         * client because there is no guarantee that we can recover from
+         * whatever messed up state the client put the connection into.
+         */
+        wsSession.onClose(cr);
     }
 
 



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

Reply via email to