-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
TCP-connection becomes unusable if request handler does not read entire request with HTTP/1.1 chunked Transfer-Encoding #10946
Comments
You seem to be describing asynchronous response generation. This means the response has started to be sent before the request is fully read. Knowing this wont help you though. Your description of the problem is a very common scenario with spring / rest libraries that use JSON or XML. Depending on your chosen JSON library you should look for the configuration options to read to EOF (and possibly throw an exception if more content appears after the close of the JSON document). Example from FasterXML/jackson-jaxrs-providers#108 public ObjectMapper restObjectMapper() {
ObjectMapper restObjectMapper = new ObjectMapper();
restObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
restObjectMapper.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS); // <-- the key change
return restObjectMapper;
} |
Yes it is incorrectly implemented. See also: |
Just some extra info. If a handler fully generates the response and completes without reading all the content, then Jetty will make an attempt to read the content, so the connection can be reused. However, Jetty will not block doing so, thus it depends on the state of connection if it can be used again. Thus a good handler should always strive to read all the request content if it wants the connection to be reused. |
Thank you for your comments, especially to @joakime, the json-deserialization-config did work wonders. |
Jetty version(s)
12.0.3
Jetty Environment
core
Java version/vendor
openjdk 21-ea 2023-09-19
OpenJDK Runtime Environment (build 21-ea+35-Ubuntu-1ubuntu122.04)
OpenJDK 64-Bit Server VM (build 21-ea+35-Ubuntu-1ubuntu122.04, mixed mode, sharing)
OS type/version
Linux
Description
If using
HTTP/1.1
withTransfer-Encoding: chunked
and the request handler does not read all chunks before responding the TCP-connection becomes unusable for subsequent requests.Note that this may happen with jersey and spring-mvc: For e.g. JSON payloads, a response is sent as soon as the request payload was fully parsed. This means that for HTTP/1.1 chunked transfer-encoding a response may be sent without reading the zero-length terminating chunk.
Still, I'm not sure if the request-handlers in those frameworks should be considered incorrectly implemented. Please advise.
Excerpts from log:
After a correctly processed request (i.e. where the entire request was processed) I see:
If only part of the request was processed I see:
Full log: server.log
How to reproduce?
I created a minimal test-case:
https://github.com/fbieler/jetty-test
The text was updated successfully, but these errors were encountered: