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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 9cb7faf4c1 Harden the calls the completion handlers for vectored I/O
9cb7faf4c1 is described below

commit 9cb7faf4c157d54c48eefda852006cd1fedcfc7b
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 30 10:23:19 2026 +0000

    Harden the calls the completion handlers for vectored I/O
    
    The completion handlers won't throw in normal Tomcat usage. Custom code
    that calls SocketWrapperBase directly with custom handlers that throw
    will benefit from this. That seems like an unlikely scenario but the
    try/finally block is cheap.
---
 .../apache/tomcat/util/net/SocketWrapperBase.java  | 40 +++++++++++++---------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java 
b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
index 57ad4baf19..bd5a7e2bb5 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -1358,14 +1358,18 @@ public abstract class SocketWrapperBase<E> {
                         state.state = currentState;
                     }
                     state.end();
-                    if (completion && state.handler != null && 
state.callHandler.compareAndSet(true, false)) {
-                        state.handler.completed(Long.valueOf(state.nBytes), 
state.attachment);
-                    }
-                    synchronized (state) {
-                        state.completionDone = true;
-                        if (notify) {
-                            state.state = currentState;
-                            state.notify();
+                    try {
+                        if (completion && state.handler != null && 
state.callHandler.compareAndSet(true, false)) {
+                            
state.handler.completed(Long.valueOf(state.nBytes), state.attachment);
+                        }
+                    } finally {
+                        // Always update the state so a caller waiting for the 
handler is never left waiting
+                        synchronized (state) {
+                            state.completionDone = true;
+                            if (notify) {
+                                state.state = currentState;
+                                state.notify();
+                            }
                         }
                     }
                 } else {
@@ -1404,14 +1408,18 @@ public abstract class SocketWrapperBase<E> {
                 state.state = state.isInline() ? CompletionState.ERROR : 
CompletionState.DONE;
             }
             state.end();
-            if (state.handler != null && state.callHandler.compareAndSet(true, 
false)) {
-                state.handler.failed(exc, state.attachment);
-            }
-            synchronized (state) {
-                state.completionDone = true;
-                if (notify) {
-                    state.state = state.isInline() ? CompletionState.ERROR : 
CompletionState.DONE;
-                    state.notify();
+            try {
+                if (state.handler != null && 
state.callHandler.compareAndSet(true, false)) {
+                    state.handler.failed(exc, state.attachment);
+                }
+            } finally {
+                // Always update the state so a caller waiting for the handler 
is never left waiting
+                synchronized (state) {
+                    state.completionDone = true;
+                    if (notify) {
+                        state.state = state.isInline() ? CompletionState.ERROR 
: CompletionState.DONE;
+                        state.notify();
+                    }
                 }
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to