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

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


The following commit(s) were added to refs/heads/10.1.x by this push:
     new e7f902bb73 Handle response committed when processing read error
e7f902bb73 is described below

commit e7f902bb73c15a75e153c4a25036eabe788d3bb6
Author: remm <r...@apache.org>
AuthorDate: Tue Apr 9 09:58:22 2024 +0200

    Handle response committed when processing read error
    
    BZ68862
---
 java/org/apache/catalina/connector/InputBuffer.java | 16 ++++++++++++++--
 webapps/docs/changelog.xml                          |  4 ++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/connector/InputBuffer.java 
b/java/org/apache/catalina/connector/InputBuffer.java
index 03c9586630..e22ef9694c 100644
--- a/java/org/apache/catalina/connector/InputBuffer.java
+++ b/java/org/apache/catalina/connector/InputBuffer.java
@@ -332,9 +332,21 @@ public class InputBuffer extends Reader implements 
ByteChunk.ByteInputChannel, A
         Response response = request.getResponse();
         request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
         if (e instanceof SocketTimeoutException) {
-            response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT);
+            try {
+                response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT);
+            } catch(IllegalStateException ex) {
+                // Response already committed
+                response.setStatus(HttpServletResponse.SC_REQUEST_TIMEOUT);
+                response.setError();
+            }
         } else {
-            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            try {
+                response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            } catch(IllegalStateException ex) {
+                // Response already committed
+                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+                response.setError();
+            }
         }
     }
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5c21e3bb99..f15e82d6ef 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -122,6 +122,10 @@
         file via the Servlet API and the file is larger than
         <code>Integer.MAX_VALUE</code>. (markt)
       </fix>
+      <fix>
+        <bug>68862</bug>: Handle possible response commit when processing read
+        errors. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to