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

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


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

commit a0c6664a4791920e658b4769df7bb76fadb058c2
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 77f62ca38e..91be300eb2 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -1359,14 +1359,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 {
@@ -1405,14 +1409,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