users@jersey.java.net

Re: [Jersey] Re: Hangs when trying to read an entity

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 9 Aug 2010 08:22:02 +0200

On Aug 6, 2010, at 7:16 PM, Imran M Yousuf wrote:

> Hi,
>
> I have bypassed the problem by switching to Apache Http based Jersey
> Client. The changes required were -
> http://github.com/imyousuf/smart-util/commit/1de6cbed2238852cc2404da988ee78c944943581
>
> I am still interested to know how to solve the main problem, please
> help!
>

I suspect this is an issue with the HttpURLConnection implementation
an the server responding with a slightly malformed response that the
Apache HTTP client can recover from. From the both thread dumps it
shows that a thread is waiting on a read:

"main" prio=10 tid=0x091fdc00 nid=0x520f runnable [0xb6b5e000]
    java.lang.Thread.State: RUNNABLE
         at java.net.SocketInputStream.socketRead0(Native Method)
         at java.net.SocketInputStream.read(SocketInputStream.java:129)
         at java.io.BufferedInputStream.fill(BufferedInputStream.java:
218)
         at java.io.BufferedInputStream.read1(BufferedInputStream.java:
258)
         at java.io.BufferedInputStream.read(BufferedInputStream.java:
317)
         - locked <0xa8391158> (a java.io.BufferedInputStream)
         at
sun
.net
.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:
525)
         at
sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:
582)
         at
sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:669)
         - locked <0xa83911a8> (a sun.net.www.http.ChunkedInputStream)
         at java.io.FilterInputStream.read(FilterInputStream.java:116)
         at sun.net.www.protocol.http.HttpURLConnection
$HttpInputStream.read(HttpURLConnection.java:2512)
         at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
         at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
         at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
         - locked <0xa8391268> (a java.io.InputStreamReader)
         at java.io.InputStreamReader.read(InputStreamReader.java:167)



There is a bug in HttpURLConnection where if you make a POST/PUT
request and the server returns a 204 response with chunked encoding
and you make a subsequent GET the client hangs. I cannot recall the
bug number or if it was fixed in a JDK release.

Did you make just one request or say a PUT then a GET?

Paul.