[ 
https://issues.apache.org/jira/browse/CAMEL-27265?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-27265:
--------------------------------
    Fix Version/s: 4.24.0

> camel-netty-http - chunked requests get no response on the shared HTTP 
> server, and with disableStreamCache when the route does not read the body
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27265
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27265
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-netty-http
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>             Fix For: 4.24.0
>
>
> h3. What happens
> *Shared HTTP server* ({{nettySharedHttpServer}}, default {{chunked=true}}): 
> the pipeline streams the body of a chunked request ({{Transfer-Encoding: 
> chunked}}, as HTTP clients send a body of unknown length) through a pipe that 
> the I/O thread both writes and reads, as the routes of the shared server run 
> on the I/O thread. The request gets no response, and the other connections 
> served by that I/O thread get no response either. This also happens when the 
> route does not read the body (stream caching reads it first; with 
> {{noStreamCaching}}, once the body is larger than the 1 KB pipe buffer), and 
> when no route matches the path: the 404 is sent, then the I/O thread waits to 
> write the rest of a body larger than 1 KB into the pipe.
> *Shared HTTP server with {{chunked=false}}*: the pipeline has no 
> {{HttpObjectAggregator}}, so the handlers, which expect a full or a streamed 
> request, fail on the {{HttpRequest}} and {{HttpContent}} parts (for example 
> {{ClassCastException: DefaultHttpContent cannot be cast to 
> InboundStreamHttpRequest}}), and the connection is closed without a response 
> for every request, also a {{GET}}.
> *Server of an endpoint with {{disableStreamCache=true}}*: the body of a 
> chunked request is streamed through the same pipe. The route runs on the 
> executor service by default, so a route that reads the body works, but:
> * when the route does not read the body (or no route matches the path), the 
> I/O thread waits for ever to write more than 1 KB into the pipe, so the 
> response is not sent and the other connections of that I/O thread are not 
> served;
> * with {{usingExecutorService=false}}, the route runs on the I/O thread and a 
> route that reads the body waits for ever;
> * the pipe is created once per connection and closed when the route has read 
> the first body, so a second chunked request on a kept-alive connection fails 
> with {{IOException: Pipe closed}} (500);
> * while the route reads, the I/O thread waits for it each time the 1 KB pipe 
> buffer is full, and serves no other connection meanwhile.
> h3. How to reproduce
> Send {{POST /foo}} with {{Transfer-Encoding: chunked}} to a route on a shared 
> HTTP server, for example the test 
> {{NettySharedHttpServerChunkedRequestTest}}: no response within 5 seconds, 
> and a {{GET}} after it gets no response either (with one I/O thread).
> h3. Fix
> * The shared HTTP server always aggregates a request, also a chunked one, 
> before the route is called, as the server of an endpoint does by default, and 
> always has the outbound streamer for streamed responses. The {{chunked}} 
> option is no longer used ({{chunked=false}} works like the default).
> * The server of an endpoint streams a chunked request with 
> {{disableStreamCache=true}} only when the route runs on the executor service; 
> with {{usingExecutorService=false}} the request is aggregated.
> * {{HttpInboundStreamHandler}} hands the chunks to the reader without making 
> the I/O thread wait: each message gets its own stream; when 64 KB of the body 
> wait to be read, it stops reading from the connection, and reads again when 
> the reader has caught up; the consumer closes the stream when the exchange is 
> done, and the rest of an unread body is then discarded, so the connection can 
> be used for the next request. A streamed reply (a reply body that is an 
> {{InputStream}}, for example the request body sent back, as it is or in 
> another stream) is written after the exchange is done and may read the 
> stream, so the stream is then closed once the reply is written. Reading the 
> stream on the I/O thread of its connection fails with an {{IOException}} 
> instead of waiting for ever, and a connection closed before the end of the 
> body fails the stream instead of ending it.
> _Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to