This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new d47c40e875 Harden the calls the completion handlers for vectored I/O
d47c40e875 is described below
commit d47c40e875ad8f36cb677dd936c9880e4cbf2e24
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 0b7c79dcb8..cfd2afbd0f 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -1397,14 +1397,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 {
@@ -1443,14 +1447,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]