-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Reactive stack on Tomcat does not handle chunked transfer encoding correctly #32427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So far, I am not capable of reproducing the issue with the linked sample. Could you please specify which OS and JVM versions you are using? |
Thanks for looking into this issue. I observe the test failure using Microsoft Windows 11 Pro (10.0.22631 Build 22631) and OpenJDK 64-Bit Server VM 17.0.8.1 (Temurin). It doesn't appear to be reproducible on Linux, however. Note: The |
I can verify that the tests fails under Windows 10 as well 11 (but not MacOS nor Linux). I can also add that the test succeeds with Jetty as well as Undertow; just not Tomcat. |
@markt-asf, does @jshs 's theory about the |
Additionally, the test succeeds when using a |
@poutsma The theory that Tomcat doesn't handle a non-blocking read of a chunk body if a partial chunk header is received looks plausible. I'll create a Tomcat unit test to simulate that scenario and report back. |
@poutsma Confirmed. It was a Tomcat bug. The bug has been fixed in all currently supported branches and will be included from the May releases. |
Thank you, @markt-asf. Is there an issue we can to link to here? |
No issue, but this is the key commit for main: apache/tomcat@cbed8e1 |
Summary
HTTP 1.1 request bodies using
Transfer-Encoding: chunked
are sometimes rejected when running a reactive servlet on top of Tomcat.This affects at least Spring Boot 3.2.3 when combining the
webflux
andtomcat
starters.Example
A complete code base to reproduce the problem is available here.
It consists of a simple server application with a POST endpoint:
and a client that streams a request to this endpoint:
The expected outcome is that the server responds as asserted. Instead, we observe a prematurely closed connection on the client and the following exception on the server:
(others might be possible)
This example was extracted from a more complex application where we first noticed the problem, hence the artificial client setup.
Remarks
The above example is potentially a flaky test, although I can reliably reproduce the issue on my machine. The problem does not seem to occur with Undertow, nor if MVC is used on the server.
My hypothesis is that the Coyote HTTP/1.1 connector does not support the combination of a non-blocking socket and chunked transfer encoding. When parsing chunk headers or the CRLF sequence after each chunk, a read size of 0 results in the request being aborted:
These parsers would need to store their state and yield control (like
doRead
) if no input is available at the socket.The text was updated successfully, but these errors were encountered: