HttpComponents HttpAsyncClient 缺少内容

问题描述

我遇到间歇性问题,我没有收到完整的响应实体,所以我最终超时。响应在几毫秒内返回,我看到正在使用的内容,但它没有达到 Content-Length 标头,因此超时开始。我正在调用的服务归第 3 方所有,他们说整个正文是在其中发送的我在请求和响应标头之间看到的时间范围。是否有我遗漏的可能导致此类行为的配置?

版本
Java:OpenJDK 11.0.6+10-LTS
HttpAsyncclient: 4.1.4
HttpCore-蔚来:4.4.13

客户端配置

IOReactorConfig reactorConfig = IOReactorConfig.custom()
    .setIoThreadCount(50)
    .setSoTimeout(15_000)
    .setConnectTimeout(30_000)
    .setSoKeepAlive(true)
    .setSoLinger(0)
    .setSoReuseAddress(true)
    .setTcpNoDelay(true)
    .build();

DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(reactorConfig);

SSLIOSessionStrategy sslioSessionStrategy = new SSLIOSessionStrategy(
    SSLContext.getDefault(),new String[] {"TLSv1.2"},null,SSLIOSessionStrategy.getDefaultHostnameVerifier()
);

Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create()
    .register("http",NoopIOSessionStrategy.INSTANCE)
    .register("https",sslioSessionStrategy)
    .build();

PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(
    ioReactor,iosessionFactoryRegistry,-1,TimeUnit.MILLISECONDS
);
connectionManager.setMaxTotal(1_000);
connectionManager.setDefaultMaxPerRoute(1_000);

CloseableHttpAsyncclient httpAsyncclient = HttpAsyncclients.custom()
    .setUserAgent("HttpAsyncclient")
    .setConnectionManager(connectionManager)
    .build();

电线日志

2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalHttpAsyncclient -- {} - [exchange: 33] Connection allocated: CPoolProxy{http-outgoing-32 [ACTIVE]}
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:]: Set attribute http.nio.exchange-handler
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:]: Event set [w]
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:]: Set timeout 60000
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE]: Connected
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:]: Set attribute http.nio.http-exchange-state
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalHttpAsyncclient -- {} - [exchange: 33] Start connection routing
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 Upgrade session 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][174]
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalHttpAsyncclient -- {} - [exchange: 33] route completed
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Connection route established
2021-07-23 14:55:53,999 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Attempt 1 to execute request
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Target auth state: UNCHALLENGED
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Proxy auth state: UNCHALLENGED
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][174]: Set timeout 15000
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 >> POST /path HTTP/1.1
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 >> Content-Type: application/x-www-form-urlencoded; charset=UTF-8
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 >> Content-Length: 2244
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 >> Host: host
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 >> Connection: Keep-Alive
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 >> User-Agent: HttpAsyncclient
2021-07-23 14:55:54,000 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][174]: Event set [w]
2021-07-23 14:55:54,075 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] Output ready
2021-07-23 14:55:54,075 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] produce content
2021-07-23 14:55:54,075 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Request completed
2021-07-23 14:55:54,075 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] [content length: 2244; pos: 2244; completed: true]
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][2793]: 2764 bytes written
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "POST /path HTTP/1.1[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "Content-Type: application/x-www-form-urlencoded; charset=UTF-8[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "Content-Length: 2244[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "Host: host[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "Connection: Keep-Alive[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "User-Agent: HttpAsyncclient[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "[\r][\n]"
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 >> "..."
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] Request ready
2021-07-23 14:55:54,076 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:w][ACTIVE][r][NOT_HANDSHAKING][0][0][0]: Event cleared [w]
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0]: 679 bytes read
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "HTTP/1.1 200 OK[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "Date: Fri,23 Jul 2021 21:55:54 GMT[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "Content-Length: 32311[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "Content-Type: text/xml[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "id: 3557dfeb-5eaa-a184-aa1a-549c0a6a864b[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "timestamp: 1627077354171[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "loggingId: b8b97947a005bc82[\r][\n]"ZyqmZAE1Zyw7ArPVb1xjlQmN3ILL1sgY[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "[\r][\n]"
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << HTTP/1.1 200 OK
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << Date: Fri,23 Jul 2021 21:55:54 GMT
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << Content-Length: 32311
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << Content-Type: text/xml
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << id: 3557dfeb-5eaa-a184-aa1a-549c0a6a864b
2021-07-23 14:55:54,181 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << timestamp: 1627077354171
2021-07-23 14:55:54,182 -0700 -- httpasyncclient-33 org.apache.http.headers -- {} - http-outgoing-32 << loggingId: b8b97947a005bc82
2021-07-23 14:55:54,182 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] Response received
2021-07-23 14:55:54,182 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Response received HTTP/1.1 200 OK
2021-07-23 14:55:54,183 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] Input ready
2021-07-23 14:55:54,183 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Consume content
2021-07-23 14:55:54,183 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0]: 0 bytes read
2021-07-23 14:55:54,183 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] [content length: 32311; pos: 0; completed: false]
2021-07-23 14:55:54,183 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][812][0][0]: 15752 bytes read
2021-07-23 14:55:54,183 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "..."
2021-07-23 14:55:54,186 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][812][0][0]: 0 bytes read
2021-07-23 14:55:54,186 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] [content length: 32311; pos: 15752; completed: false]
2021-07-23 14:55:54,201 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] Input ready
2021-07-23 14:55:54,201 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.MainClientExec -- {} - [exchange: 33] Consume content
2021-07-23 14:55:54,201 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0]: 16384 bytes read
2021-07-23 14:55:54,201 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "..."
2021-07-23 14:55:54,203 -0700 -- httpasyncclient-33 org.apache.http.wire -- {} - http-outgoing-32 << "..."
2021-07-23 14:55:54,203 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.conn.ManagednHttpClientConnectionImpl -- {} - http-outgoing-32 10.187.155.22:26784<->17.000.00.00:443[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0]: 0 bytes read
2021-07-23 14:55:54,203 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] [content length: 32311; pos: 32136; completed: false]
2021-07-23 14:56:09,217 -0700 -- httpasyncclient-33 org.apache.http.impl.nio.client.InternalIOdispatch -- {} - http-outgoing-32 [ACTIVE] Timeout

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)