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

remm 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 0970fbaa12 Handle response committed when processing read error
0970fbaa12 is described below

commit 0970fbaa12a45b31117b94e2781f8b7fa5c37f07
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 b9f67768a9..162c6fd314 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 358930589e..9f6d7f51b5 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -139,6 +139,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