You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/10/16 13:16:52 UTC
svn commit: r1532722 -
/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
Author: markt
Date: Wed Oct 16 11:16:52 2013
New Revision: 1532722
URL: http://svn.apache.org/r1532722
Log:
Don't call the onError() method of the endpoint if the WebSocket close message cannot be sent for abnormal closure as this is not unexpected.
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.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=1532722&r1=1532721&r2=1532722&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Wed Oct 16 11:16:52 2013
@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.atomic.AtomicLong;
import javax.websocket.CloseReason;
+import javax.websocket.CloseReason.CloseCode;
import javax.websocket.CloseReason.CloseCodes;
import javax.websocket.DeploymentException;
import javax.websocket.Endpoint;
@@ -463,7 +464,8 @@ public class WsSession implements Sessio
private void sendCloseMessage(CloseReason closeReason) {
// 125 is maximum size for the payload of a control message
ByteBuffer msg = ByteBuffer.allocate(125);
- msg.putShort((short) closeReason.getCloseCode().getCode());
+ CloseCode closeCode = closeReason.getCloseCode();
+ msg.putShort((short) closeCode.getCode());
String reason = closeReason.getReasonPhrase();
if (reason != null && reason.length() > 0) {
@@ -480,7 +482,13 @@ public class WsSession implements Sessio
log.debug(sm.getString("wsSession.sendCloseFail"), ioe);
}
wsRemoteEndpoint.close();
- localEndpoint.onError(this, ioe);
+ // Failure to send a close message is not unexpected in the case of
+ // an abnormal closure (usually triggered by a failure to read/write
+ // from/to the client. In this case do not trigger the endpoint's
+ // error handling
+ if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
+ localEndpoint.onError(this, ioe);
+ }
} finally {
webSocketContainer.unregisterSession(localEndpoint, this);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org