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

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


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

commit bc564641b782a27bcf0042e453e9f4ccf44b02ea
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 91201d2..c7e3319 100644
--- a/java/org/apache/tomcat/websocket/WsSession.java
+++ b/java/org/apache/tomcat/websocket/WsSession.java
@@ -598,6 +598,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) {
@@ -605,13 +607,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