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

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

commit 0ff1ed325d2a35c64a12c36f2bfd1959f66413f2
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Feb 24 15:41:25 2021 +0000

    Avoid attempting to write an error report if I/O is not allowed
---
 .../apache/catalina/valves/ErrorReportValve.java   | 28 ++++++++++++++--------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/catalina/valves/ErrorReportValve.java 
b/java/org/apache/catalina/valves/ErrorReportValve.java
index c3fb116..74ccc1f 100644
--- a/java/org/apache/catalina/valves/ErrorReportValve.java
+++ b/java/org/apache/catalina/valves/ErrorReportValve.java
@@ -83,17 +83,25 @@ public class ErrorReportValve extends ValveBase {
         if (response.isCommitted()) {
             if (response.setErrorReported()) {
                 // Error wasn't previously reported but we can't write an error
-                // page because the response has already been committed. 
Attempt
-                // to flush any data that is still to be written to the client.
-                try {
-                    response.flushBuffer();
-                } catch (Throwable t) {
-                    ExceptionUtils.handleThrowable(t);
+                // page because the response has already been committed.
+
+                // See if IO is allowed
+                AtomicBoolean ioAllowed = new AtomicBoolean(true);
+                response.getCoyoteResponse().action(ActionCode.IS_IO_ALLOWED, 
ioAllowed);
+
+                if (ioAllowed.get()) {
+                    // I/O is currently still allowed. Flush any data that is
+                    // still to be written to the client.
+                    try {
+                        response.flushBuffer();
+                    } catch (Throwable t) {
+                        ExceptionUtils.handleThrowable(t);
+                    }
+                    // Now close immediately to signal to the client that
+                    // something went wrong
+                    response.getCoyoteResponse().action(ActionCode.CLOSE_NOW,
+                            
request.getAttribute(RequestDispatcher.ERROR_EXCEPTION));
                 }
-                // Close immediately to signal to the client that something 
went
-                // wrong
-                response.getCoyoteResponse().action(ActionCode.CLOSE_NOW,
-                        
request.getAttribute(RequestDispatcher.ERROR_EXCEPTION));
             }
             return;
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to