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

jan updated HTTPCORE-614:
-------------------------
    Description: 
Suppose the following code:

 
{code:java}
CloseableHttpResponse response =...
InputStream i = response.getEntity().getContent();
{code}
With Apache httpclient 4.5, it was possible to do 

 
{code:java}
response.close();
i.close();
{code}
 

With Apache 4.5.1+ it is no longer possible. For instance, with 4.5.9, it 
throws:

 
{noformat}
Caused by: org.apache.http.MalformedChunkCodingException: CRLF expected at end 
of chunkCaused by:
 org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk 
at 
org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:250)
 
at 
org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
 
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183) 
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210) 
at 
org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:312) 
at 
org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
 
at 
org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
 
at 
org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172) 
at java.io.BufferedInputStream.close(BufferedInputStream.java:483) 
at java.io.FilterInputStream.close(FilterInputStream.java:181){noformat}
 

The underlying connection is closed and ChunkedInputStream is unhappy.

The advised solution was to switch the close order to:

 
{code:java}
i.close()
response.close().
{code}
 

But in this case, when i.close() is called, the thread is stuck on reading from 
the connection since the ChunkedInputStream tries to read from the socket:
{noformat}
 java.lang.Thread.State: RUNNABLE
 at java.net.SocketInputStream.socketRead0(Native Method)
 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
 at java.net.SocketInputStream.read(SocketInputStream.java:171)
 at java.net.SocketInputStream.read(SocketInputStream.java:141)
 at 
org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
 at 
org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
 at 
org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
 at 
org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:261)
 at 
org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
 at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183)
 at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210)
 at 
org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:312)
 at 
org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
 at 
org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
 at 
org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172)
 at java.io.BufferedInputStream.close(BufferedInputStream.java:483)
 at java.io.FilterInputStream.close(FilterInputStream.java:181)

{noformat}
What would be the correct solution to close the connection?

The brief history of the issue is 
[[[https://github.com/eclipse-ee4j/jersey/issues/4321|here|https://github.com/eclipse-ee4j/jersey/issues/4321]].

 

 

 

 

  was:
Suppose the following code:

 
{code:java}
CloseableHttpResponse response =...
InputStream i = response.getEntity().getContent();
{code}
With Apache httpclient 4.5, it was possible to do 

 
{code:java}
response.close();
i.close();
{code}
 

With Apache 4.5.1+ it is no longer possible. For instance, with 4.5.9, it 
throws:

 
{noformat}
Caused by: org.apache.http.MalformedChunkCodingException: CRLF expected at end 
of chunkCaused by:
 org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk 
at 
org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:250)
 
at 
org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
 
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183) 
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210) 
at 
org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:312) 
at 
org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
 
at 
org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
 
at 
org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172) 
at java.io.BufferedInputStream.close(BufferedInputStream.java:483) 
at java.io.FilterInputStream.close(FilterInputStream.java:181){noformat}
 

The underlying connection is closed and ChunkedInputStream is unhappy.

The advised solution was to switch the close order to:

 
{code:java}
i.close()
response.close().
{code}
 

But in this case, when i.close() is called, the thread is stuck on reading from 
the connection since the ChunkedInputStream tries to read from the socket:
{noformat}
 java.lang.Thread.State: RUNNABLE
 at java.net.SocketInputStream.socketRead0(Native Method)
 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
 at java.net.SocketInputStream.read(SocketInputStream.java:171)
 at java.net.SocketInputStream.read(SocketInputStream.java:141)
 at 
org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
 at 
org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
 at 
org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
 at 
org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:261)
 at 
org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
 at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183)
 at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210)
 at 
org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:312)
 at 
org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
 at 
org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
 at 
org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172)
 at java.io.BufferedInputStream.close(BufferedInputStream.java:483)
 at java.io.FilterInputStream.close(FilterInputStream.java:181)

{noformat}
What would be the correct solution to close the connection?

The brief history of the issue is 
[here|[https://github.com/eclipse-ee4j/jersey/issues/4321]].

 

 

 

 


> ChunkedInputStream makes connection unclosable?
> -----------------------------------------------
>
>                 Key: HTTPCORE-614
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-614
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>            Reporter: jan
>            Priority: Major
>
> Suppose the following code:
>  
> {code:java}
> CloseableHttpResponse response =...
> InputStream i = response.getEntity().getContent();
> {code}
> With Apache httpclient 4.5, it was possible to do 
>  
> {code:java}
> response.close();
> i.close();
> {code}
>  
> With Apache 4.5.1+ it is no longer possible. For instance, with 4.5.9, it 
> throws:
>  
> {noformat}
> Caused by: org.apache.http.MalformedChunkCodingException: CRLF expected at 
> end of chunkCaused by:
>  org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk 
> at 
> org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:250)
>  
> at 
> org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
>  
> at 
> org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183) 
> at 
> org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210) 
> at 
> org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:312) 
> at 
> org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
>  
> at 
> org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
>  
> at 
> org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172)
>  
> at java.io.BufferedInputStream.close(BufferedInputStream.java:483) 
> at java.io.FilterInputStream.close(FilterInputStream.java:181){noformat}
>  
> The underlying connection is closed and ChunkedInputStream is unhappy.
> The advised solution was to switch the close order to:
>  
> {code:java}
> i.close()
> response.close().
> {code}
>  
> But in this case, when i.close() is called, the thread is stuck on reading 
> from the connection since the ChunkedInputStream tries to read from the 
> socket:
> {noformat}
>  java.lang.Thread.State: RUNNABLE
>  at java.net.SocketInputStream.socketRead0(Native Method)
>  at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
>  at java.net.SocketInputStream.read(SocketInputStream.java:171)
>  at java.net.SocketInputStream.read(SocketInputStream.java:141)
>  at 
> org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
>  at 
> org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
>  at 
> org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
>  at 
> org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:261)
>  at 
> org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
>  at 
> org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183)
>  at 
> org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:210)
>  at 
> org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:312)
>  at 
> org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:142)
>  at 
> org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
>  at 
> org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:172)
>  at java.io.BufferedInputStream.close(BufferedInputStream.java:483)
>  at java.io.FilterInputStream.close(FilterInputStream.java:181)
> {noformat}
> What would be the correct solution to close the connection?
> The brief history of the issue is 
> [[[https://github.com/eclipse-ee4j/jersey/issues/4321|here|https://github.com/eclipse-ee4j/jersey/issues/4321]].
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to