This is an automated email from the ASF dual-hosted git repository.
markt-asf 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 2ea7a2211f Harden the calls the completion handlers for vectored I/O
2ea7a2211f is described below
commit 2ea7a2211f08eb88643af8e0863be570c56fd94d
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]