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 bdde66827e Review "Fix silent loss of error reports in 
ProxyErrorReportValve ..."
bdde66827e is described below

commit bdde66827e8fb2285f726ffebe9dc6502005055f
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Oct 29 15:25:35 2026 +0000

    Review "Fix silent loss of error reports in ProxyErrorReportValve ..."
    
    Reset the response and use the fall-back if the proxy fails before the
    response is committed.
    
    Abort the connection if the proxy fails after the response is committed
---
 .../catalina/valves/ProxyErrorReportValve.java     | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/valves/ProxyErrorReportValve.java 
b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
index ed40596203..7c4503f0e3 100644
--- a/java/org/apache/catalina/valves/ProxyErrorReportValve.java
+++ b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
@@ -301,11 +301,24 @@ public class ProxyErrorReportValve extends 
ErrorReportValve {
                 if (log.isWarnEnabled()) {
                     log.warn(sm.getString("proxyErrorReportValve.error", 
urlString), failure);
                 }
-                // Discard any target metadata that was applied to this 
response before the failure, so that a stale
-                // Content-Length cannot truncate or suppress the fallback 
report. Fall back to the default error
-                // report rather than returning an empty response. The 
reported flag is consumed by super.report().
-                response.setContentLength(-1);
-                super.report(request, response, throwable);
+                if (response.isCommitted()) {
+                    /*
+                     * Headers have already been sent. Need to abort the 
connection so the client sees an incomplete
+                     * response.
+                     */
+                    response.setErrorReported();
+                    response.getCoyoteResponse().action(ActionCode.CLOSE_NOW, 
failure);
+                } else {
+                    /*
+                     * Discard any target metadata that was applied to this 
response before the failure, so that a stale
+                     * Content-Length cannot truncate or suppress the fallback 
report. Fall back to the default error
+                     * report rather than returning an empty response. The 
reported flag is consumed by super.report().
+                     */
+                    response.resetBuffer();
+                    response.setContentType(null);
+                    response.setContentLength(-1);
+                    super.report(request, response, throwable);
+                }
             }
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to