This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new cacd49a  Follow-up to fix for 65763.
cacd49a is described below

commit cacd49a38701bdab49444047990dc05d52edcc3a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jan 7 23:24:09 2022 +0000

    Follow-up to fix for 65763.
    
    Improving the handling of timeouts meant that code that was previously
    skipped due to an uncaught exception was no longer skipped and that
    broke some tests. Ensure close message and/or notifications are only
    sent once.
---
 java/org/apache/tomcat/websocket/WsSession.java | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/WsSession.java 
b/java/org/apache/tomcat/websocket/WsSession.java
index dc952c1..2234fb0 100644
--- a/java/org/apache/tomcat/websocket/WsSession.java
+++ b/java/org/apache/tomcat/websocket/WsSession.java
@@ -691,6 +691,8 @@ public class WsSession implements Session {
             if (log.isDebugEnabled()) {
                 log.debug(sm.getString("wsSession.doClose", id));
             }
+
+            // This will trigger a flush of any batched messages.
             try {
                 wsRemoteEndpoint.setBatchingAllowed(false);
             } catch (IOException e) {
@@ -698,13 +700,20 @@ public class WsSession implements Session {
                 fireEndpointOnError(e);
             }
 
-            state = State.OUTPUT_CLOSED;
+            /*
+             * If the flush above fails the error handling could call this
+             * method recursively. Without this check, the close message and
+             * notifications could be sent multiple times.
+             */
+            if (state != State.OUTPUT_CLOSED) {
+                state = State.OUTPUT_CLOSED;
 
-            sendCloseMessage(closeReasonMessage);
-            if (closeSocket) {
-                wsRemoteEndpoint.close();
+                sendCloseMessage(closeReasonMessage);
+                if (closeSocket) {
+                    wsRemoteEndpoint.close();
+                }
+                fireEndpointOnClose(closeReasonLocal);
             }
-            fireEndpointOnClose(closeReasonLocal);
         }
 
         IOException ioe = new 
IOException(sm.getString("wsSession.messageFailed"));

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

Reply via email to