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 b078f25139 Review "Report errors to upgraded connection WriteListeners
at most..."
b078f25139 is described below
commit b078f25139a0661940218dc42d42ad3136274379
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 2 10:11:40 2026 +0000
Review "Report errors to upgraded connection WriteListeners at most..."
Make errorReported guard atomic.
Fix possible NPE in onError()
---
.../coyote/http11/upgrade/UpgradeServletInputStream.java | 14 ++++++++------
.../coyote/http11/upgrade/UpgradeServletOutputStream.java | 8 ++++----
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git
a/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
b/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
index 90505e6b2b..ea7e78806b 100644
--- a/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
+++ b/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
@@ -17,6 +17,7 @@
package org.apache.coyote.http11.upgrade;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
@@ -72,7 +73,7 @@ public class UpgradeServletInputStream extends
ServletInputStream {
* Whether the error call-back has been triggered. No further call-backs
* are permitted once the error call-back has been triggered.
*/
- private volatile boolean errorReported = false;
+ private final AtomicBoolean errorReported = new AtomicBoolean();
/**
* Whether the all data read call-back has been triggered. It is only
@@ -127,10 +128,12 @@ public class UpgradeServletInputStream extends
ServletInputStream {
try {
ready = Boolean.valueOf(socketWrapper.isReadyForRead());
+ return ready.booleanValue();
} catch (IOException ioe) {
+ this.ready = Boolean.FALSE;
onError(ioe);
}
- return ready.booleanValue();
+ return false;
}
@@ -262,7 +265,7 @@ public class UpgradeServletInputStream extends
ServletInputStream {
final void onDataAvailable() {
- if (errorReported || allDataReadReported) {
+ if (errorReported.get() || allDataReadReported) {
// No further call-backs are permitted once an error has been
// reported or once the end of the data has been reported.
return;
@@ -283,7 +286,7 @@ public class UpgradeServletInputStream extends
ServletInputStream {
if (!eof) {
listener.onDataAvailable();
}
- if (eof && !errorReported) {
+ if (eof && !errorReported.get()) {
allDataReadReported = true;
listener.onAllDataRead();
}
@@ -297,10 +300,9 @@ public class UpgradeServletInputStream extends
ServletInputStream {
final void onError(Throwable t) {
- if (listener == null || errorReported) {
+ if (listener == null || !errorReported.compareAndSet(false, true)) {
return;
}
- errorReported = true;
ClassLoader oldCL =
processor.getUpgradeToken().contextBind().bind(null);
try {
listener.onError(t);
diff --git
a/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
b/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
index 1491c496f0..761ec1e5fb 100644
--- a/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
+++ b/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
@@ -17,6 +17,7 @@
package org.apache.coyote.http11.upgrade;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.WriteListener;
@@ -83,7 +84,7 @@ public class UpgradeServletOutputStream extends
ServletOutputStream {
* Whether an error has been reported to the listener. No further
* call-backs are permitted once the error has been reported.
*/
- private volatile boolean errorReported = false;
+ private final AtomicBoolean errorReported = new AtomicBoolean();
// Start in blocking-mode
/**
@@ -254,7 +255,7 @@ public class UpgradeServletOutputStream extends
ServletOutputStream {
final void onWritePossible() {
- if (errorReported) {
+ if (errorReported.get()) {
// No further call-backs are permitted once an error has been
// reported.
return;
@@ -304,10 +305,9 @@ public class UpgradeServletOutputStream extends
ServletOutputStream {
final void onError(Throwable t) {
- if (listener == null || errorReported) {
+ if (listener == null || !errorReported.compareAndSet(false, true)) {
return;
}
- errorReported = true;
ClassLoader oldCL =
processor.getUpgradeToken().contextBind().bind(null);
try {
listener.onError(t);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]