[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]httpclient的https读超时锁死的问题,readtimeout

上一篇:[GDS]乘客类型NEG
下一篇:[备忘]IBE+接口备忘

添加日期:2018-12-12 11:38:15 快速返回   返回列表 阅读81次
现象:
定义任务不执行了,用jstack 111看线程,发现:


"jobExecutor-3" #47 prio=5 os_prio=0 tid=0x00007f3380016000 nid=0x4053 runnable [0x00007f335eeed000]
   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 sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
        at sun.security.ssl.InputRecord.read(InputRecord.java:503)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
        - locked <0x000000068925b648> (a java.lang.Object)
        at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
        at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
        - locked <0x000000068925b748> (a sun.security.ssl.AppInputStream)
        at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160)
        at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)
        at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273)
        at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
        at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
        at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
        at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
        at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
        at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:197)
        at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
        at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
        at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
        at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)



很明显,socket读时,死等中。
验证,确实,该url有问题。

修改代码,增加超时设置:


httpClient = new SSLClient();
httpPost = new HttpPost(url);
            
// 超时设置
// ConnectionRequestTimeout,从连接池获取连接的超时时间
// ConnectTimeout,连接服务器的超时时间
// SocketTimeout,传输数据的超时时间,是两个数据包之间的间隔时间,并非整体传输时间。如果一直有数据传输,不会触发此异常。
RequestConfig requestConfig = RequestConfig.custom()
                    .setConnectionRequestTimeout(5000).setConnectTimeout(5000)
                    .setSocketTimeout(10000).build();
httpPost.setConfig(requestConfig);



升级,发现问题依旧。

这段代码之前在http上试验过,是没问题的。
怀疑是https时不好使,google之,得下文:

https://tangjuntc.com/2018/05/18/http-client-ssl-handshake-socket-readtimeout/

说是httpclient的bug,在4.3.5版本已修复,
一看,我用的版本是4.4.1,有点晕~~

继续搜,得下文:

https://issues.apache.org/jira/browse/HTTPCLIENT-1478

得知,修复的不彻底,所以,升级到最新版,


<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.6</version>
</dependency>



刚要试,得通知,该URL修复了,晕倒在盒饭上~~
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved