EVALUATION
Yes, there is a bug in the HttpURLConnection implementation around how it buffers chunked ErrorStreams.
The code that does this (HttpURLConnection$ErrorStream.getErrorStream()) takes the following steps:
a) temporarily change the socket timeout
b) read from the (chunked) input stream into a buffer
c) reset the socket timeout to its original value
If the error data has been completely read then the ChunkedInputstream will call closeUnderlying(). This will try to put the connection in the keepalive cache, but may close it if there was an error or if the number of request/responses that this connection was being held open for has been exceeded. Now when we try to reset the socket timeout it will throw new SocketException("Socket is closed"). This causes getErrorStream to return null.
|