[
https://issues.apache.org/jira/browse/HTTPCLIENT-2222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17557570#comment-17557570
]
Gaojie Liu commented on HTTPCLIENT-2222:
----------------------------------------
Hi [~olegk]
Let me share the analysis I did in our env.
Here is the stacktrace I dumped when the underlying session was closed while
using 5.1.2.:
{code:java}
java.lang.Exception: Stack trace
at java.base/java.lang.Thread.dumpStack(Thread.java:1388)
at
org.apache.hc.core5.reactor.InternalDataChannel.close(InternalDataChannel.java:275)
at
org.apache.hc.core5.reactor.InternalDataChannel.close(InternalDataChannel.java:257)
at
org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onOutput(AbstractH2StreamMultiplexer.java:522)
at
org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.outputReady(AbstractH2IOEventHandler.java:74)
at
org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.outputReady(ClientH2IOEventHandler.java:39)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession.encryptData(SSLIOSession.java:588)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession.access$600(SSLIOSession.java:72)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession$1.outputReady(SSLIOSession.java:181)
at
org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:141)
at
org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
at
org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
at
org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
at
org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
at
org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
at java.base/java.lang.Thread.run(Thread.java:834) {code}
And the underlying session was closed gracefully.
[https://github.com/apache/httpcomponents-core/blob/5.1.x/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java#L543]
AbstractH2StreamMultiplexer.java will mark the connState as `SHUTDOWN` when
timeout happens, and during processing the closed sessions when serving new
requests, httpclient will throw `ConnectionClosedException`.
I will try to reproduce it locally.
*Regarding the bug fix, I was referring to this comment:*
ProtocolNegotiationException
exception, it happened at protocol negotiation phase, so it seems this issue
was fixed in the last release:
ClientH2PrefaceHandler.java
{code:java}
@Override
public void inputReady(final IOSession session, final ByteBuffer src) throws
IOException {
if (src != null) {
if (inBuf == null) {
inBuf = BufferedData.allocate(src.remaining());
}
inBuf.put(src);
}
if (preface != null) {
writeOutPreface(session);
} else {
throw new ProtocolNegotiationException("Unexpected input");
}
} {code}
H2OnlyClientProtocolNegotiator.java in 5.1.2:
{code:java}
@Override
public void inputReady(final IOSession session, final ByteBuffer src) throws
IOException {
if (src != null) {
throw new ProtocolNegotiationException("Unexpected input");
}
if (preface != null) {
writeOutPreface(session);
} else {
throw new ProtocolNegotiationException("Unexpected input");
}
} {code}
I will try to post a RB against 5.1.x branch.
Thanks
> ProtocolNegotiationException and ConnectionClosedException with httpclient5
> ---------------------------------------------------------------------------
>
> Key: HTTPCLIENT-2222
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2222
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient (async)
> Affects Versions: 5.1.2, 5.1.3
> Environment: GNU/Linux 5.4 with JDK11.
> Reporter: Gaojie Liu
> Priority: Major
>
> We are using httpclient5 to talk HTTP/2 to a Netty H2 server and we are using
> a pretty standard way to construct a HttpClient5 client as follows:
> {code:java}
> final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
> .setSoKeepAlive(true)
> .setTcpNoDelay(true)
> .setSoTimeout(Timeout.ofMilliseconds(requestTimeOutInMilliseconds))
> .setIoThreadCount(ioThreadCount)
> .build();
> final TlsStrategy tlsStrategy = skipCipherCheck ?
> VeniceClientTlsStrategyBuilder.create()
> .setSslContext(sslContext)
> .setTlsVersions(TLS.V_1_3, TLS.V_1_2)
> .build()
> : ClientTlsStrategyBuilder.create()
> .setSslContext(sslContext)
> .setTlsVersions(TLS.V_1_3, TLS.V_1_2)
> .build();
> final CloseableHttpAsyncClient client =
> HttpAsyncClients.customHttp2().setTlsStrategy(tlsStrategy)
> .setIOReactorConfig(ioReactorConfig)
> .setDefaultRequestConfig(RequestConfig.custom()
>
> .setResponseTimeout(Timeout.ofMilliseconds(requestTimeOutInMilliseconds))
>
> .setConnectionRequestTimeout(Timeout.ofMilliseconds(requestTimeOutInMilliseconds))
>
> .setConnectTimeout(Timeout.ofMilliseconds(connectTimeOutInMilliseconds))
> .build())
> .build();
> client.start(); {code}
> When we deployed this to prod, we discovered the following exceptions in the
> first 30 mins and later, it seems become more stable:
> {code:java}
> org.apache.hc.core5.http.ConnectionClosedException: Connection is closed
> at
> org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onDisconnect(AbstractH2StreamMultiplexer.java:568)
> ~[httpcore5-h2-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.disconnected(AbstractH2IOEventHandler.java:96)
> ~[httpcore5-h2-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.disconnected(ClientH2IOEventHandler.java:39)
> ~[httpcore5-h2-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.ssl.SSLIOSession$1.disconnected(SSLIOSession.java:212)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.InternalDataChannel.disconnected(InternalDataChannel.java:193)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions(SingleCoreIOReactor.java:231)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:133)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at java.lang.Thread.run(Thread.java:834)
> [?:?]org.apache.hc.core5.http2.impl.nio.ProtocolNegotiationException:
> Unexpected input
> at
> org.apache.hc.core5.http2.impl.nio.H2OnlyClientProtocolNegotiator.inputReady(H2OnlyClientProtocolNegotiator.java:133)
> ~[httpcore5-h2-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.ssl.SSLIOSession.decryptData(SSLIOSession.java:549)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:72)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.ssl.SSLIOSession$1.inputReady(SSLIOSession.java:172)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:131)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at
> org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
> ~[httpcore5-5.1.2.jar:5.1.2]
> at java.lang.Thread.run(Thread.java:834) [?:?] {code}
> Is it a known issue?
> We tried the latest release of httpclient5: 5.2-beta1, the
> ConnectionClosedException exception would happen much more frequent.
> Let me know if you need more information.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]