Author: markt Date: Mon Jan 28 17:41:19 2019 New Revision: 1852390 URL: http://svn.apache.org/viewvc?rev=1852390&view=rev Log: Ensure that the network connection is closed if the WebSocket client receives an I/O error trying to communicate with the server.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java?rev=1852390&r1=1852389&r2=1852390&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java Mon Jan 28 17:41:19 2019 @@ -116,6 +116,10 @@ public class WsFrameClient extends WsFra } + /* + * Fatal error. Usually an I/O error. Try and send notifications. Make sure + * socket is closed. + */ private final void close(Throwable t) { changeReadState(ReadState.CLOSING); CloseReason cr; @@ -125,11 +129,7 @@ public class WsFrameClient extends WsFra cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY, t.getMessage()); } - try { - wsSession.close(cr); - } catch (IOException ignore) { - // Ignore - } + wsSession.doClose(cr, cr, true); } 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=1852390&r1=1852389&r2=1852390&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Mon Jan 28 17:41:19 2019 @@ -456,6 +456,22 @@ public class WsSession implements Sessio * @param closeReasonLocal The close reason to pass to the local endpoint */ public void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal) { + doClose(closeReasonMessage, closeReasonLocal, false); + } + + + /** + * WebSocket 1.0. Section 2.1.5. + * Need internal close method as spec requires that the local endpoint + * receives a 1006 on timeout. + * + * @param closeReasonMessage The close reason to pass to the remote endpoint + * @param closeReasonLocal The close reason to pass to the local endpoint + * @param closeSocket Should the socket be closed immediately rather than waiting + * for the server to respond + */ + public void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal, + boolean closeSocket) { // Double-checked locking. OK because state is volatile if (state != State.OPEN) { return; @@ -479,6 +495,9 @@ public class WsSession implements Sessio state = State.OUTPUT_CLOSED; sendCloseMessage(closeReasonMessage); + if (closeSocket) { + wsRemoteEndpoint.close(); + } fireEndpointOnClose(closeReasonLocal); } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1852390&r1=1852389&r2=1852390&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Jan 28 17:41:19 2019 @@ -190,6 +190,10 @@ implementation completes correctly rather than silently using the hard-coded fall-back. (markt) </fix> + <fix> + Ensure that the network connection is closed if the client receives an + I/O error trying to communicate with the server. (markt) + </fix> </changelog> </subsection> <subsection name="Web applications"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org