jira-importer opened a new issue, #1131: URL: https://github.com/apache/httpcomponents-core/issues/1131
**[jan](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=supol)** opened **[HTTPCORE-614](https://issues.apache.org/jira/browse/HTTPCORE-614?redirect=false)** and commented Suppose the following code: ```java CloseableHttpResponse response =... InputStream i = response.getEntity().getContent(); ``` With Apache httpclient 4.5, it was possible to do ```java response.close(); i.close(); ``` With Apache 4.5.1+ it is no longer possible. For instance, with 4.5.9, it throws: ``` 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) ``` The underlying connection is closed and ChunkedInputStream is unhappy. The advised solution was to switch the close order to: ```java i.close() response.close(). ``` 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: ``` 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) ``` What would be the correct solution to close the connection? The brief history of the issue is at https://github.com/eclipse-ee4j/jersey/issues/4321. --- No further details from [HTTPCORE-614](https://issues.apache.org/jira/browse/HTTPCORE-614?redirect=false) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
