On Mon, 2016-08-29 at 13:49 -0700, Steven Schlansker wrote:
> Hi httpclient-users,
> 
> I am using HttpClient 4.5.2 / HttpCore 4.4.5 to connect to a streaming 
> endpoint.  The endpoint returns chunked records essentially forever.
> My application consumes these never ending records until an operator signals 
> it to stop.  The code looks something like:
> 
> try (InputStream r = openHttpConnection(...)) {
>   while (running) {
>     Record record = consumeRecord(r);
>     processRecord(record);
>   }
> }
> 
> As you'd expect, when the operator signals stop, the ChunkedInputStream is 
> closed.
> However, the implementation of ChunkedInputStream.close is pretty painful in 
> this case:
> 
> if (!eof && state != CHUNK_INVALID) {
>   // read and discard the remainder of the message
>   final byte buff[] = new byte[BUFFER_SIZE];
>   while (read(buff) >= 0) {
>   }
> }
> 
> So my thread sits forever trying to close, discarding more and more data from
> the server.
> 
> How can I abort this connection cleanly, without needing to read to the end 
> of a
> never ending stream of data from the server?
> 

There are two options:
(1) Close the response without closing the content input stream
(2) Abort the request

In both cases the underlying connection will be shut down immediately
and returned to the connection pool.

Hope this helps

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to