I'm implementing an application that communicates with the GitHub API in order to infer some statistics about projects developed currently. I chose to make the requests asynchronously, using HttpAsyncClient
.
My problem is that after I execute all requests and get all the responses from the API (around 150 of them) and I try to read the content with
String content = EntityUtils.toString(response.getEntity());
I'm getting following SSLException after ~120 responses read:
Exception in thread "main" javax.net.ssl.SSLException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:557)
at sun.security.ssl.InputRecord.read(InputRecord.java:509)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:883)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:840)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:94)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:204)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:182)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:138)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:282)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:324)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:176)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:224)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:264)
at pl.xsolve.githubmetrics.github.OwnGitHubClient.extractBodyFromResponse(OwnGitHubClient.java:117)
The problem disappears when I decrease the number of requests significantly (for instance, by half). Also, all the responses contain HTTP/1.1 200 OK
- I've checked it with response.getStatusLine()
and it works until the very end of the response list.
The problem persists even if I remove httpClient.shutdown()
in the finally
block (which is executed before reading the content).
From the stack trace, I've concluded that the exception is thrown on the line
while((l = reader.read(tmp)) != -1)
Is the entity in the HttpResponse
getting somehow outdated? Do you see an error in my reasoning? What can be the reason why first 120 responses are parsed properly and then SSLException is thrown?
Any help will be greatly appreciated :)