0

我正在实现一个与 GitHub API 通信的应用程序,以推断有关当前开发的项目的一些统计数据。我选择使用HttpAsyncClient.

我的问题是,在我执行所有请求并从 API 获取所有响应(大约 150 个)之后,我尝试使用

String content = EntityUtils.toString(response.getEntity());

在阅读了 ~120 个响应后,我收到了 SSLException:

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)

当我显着减少请求数量(例如,减少一半)时,问题就消失了。此外,所有回复都包含HTTP/1.1 200 OK- 我已经检查过它,response.getStatusLine()它一直有效到回复列表的最后。即使我httpClient.shutdown()finally块中删除(在读取内容之前执行),问题仍然存在。

从堆栈跟踪中,我得出的结论是抛出异常就行了

while((l = reader.read(tmp)) != -1)

实体在HttpResponse某种程度上已经过时了吗?你看到我的推理有误吗?前 120 个响应被正确解析然后引发 SSLException 的原因是什么?

任何帮助将不胜感激 :)

4

1 回答 1

0

这也可能取决于您的 openssl 版本。在我维护的一个 python 项目中,当人们在短时间内发出大量 SSL 请求时,我们在 openssl 0.9.8 中看到了错误。诚然,这与您的错误消息完全不同,但升级到 openssl 1.0 可能会有所帮助。

于 2013-04-02T15:26:59.040 回答