title: java.nio.BufferOverflowException in org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onInput
body: <p>Using this code to hit an HTTP/2 exposed URL:</p>
  <pre><code>        H2Config h2Config = H2Config.custom().setPushEnabled(false)
              .setCompressionEnabled(true) // Make it a prop
              .setHeaderTableSize(INIT_HEADER_TABLE_SIZE)
              .setMaxConcurrentStreams(Integer.MAX_VALUE) // no limit
              .setMaxFrameSize(INIT_MAX_FRAME_SIZE)
              .setInitialWindowSize(INIT_WINDOW_SIZE)
              .setMaxHeaderListSize(Integer.MAX_VALUE)
              .build(); // unlimited
      CloseableHttpAsyncClient asyncClient = HttpAsyncClients.customHttp2()
          .setTlsStrategy(ClientTlsStrategyBuilder.create()
                  .setSslContext(SSLContexts.createSystemDefault())
                  .setTlsVersions(TLS.V_1_2)
                  .build())
          .setH2Config(h2Config)
          .setIOReactorConfig(IOReactorConfig.custom()
                  .setSoTimeout(Timeout.ofSeconds(5))
                  .build())
          .setDefaultRequestConfig(org.apache.hc.client5.http.config.RequestConfig.custom()
                  .setConnectTimeout(Timeout.ofSeconds(5))
                  .setResponseTimeout(Timeout.ofSeconds(5))
                  .setCookieSpec(StandardCookieSpec.STRICT)
                  .build())
          .build();
      
      org.apache.hc.core5.http.HttpRequest httpGet = new BasicHttpRequest(Method.GET, new URL(&quot;XXXX&quot;).toURI());       
      BasicAsyncEntityConsumer entityConsumer = new BasicAsyncEntityConsumer();
      CompletableFuture&lt;byte[]&gt; result = new CompletableFuture&lt;&gt;();
      FutureCallback&lt;Message&lt;HttpResponse, byte[]&gt;&gt; callback = new Callback2&lt;byte[]&gt;(result, &quot;Test&quot;);
      BasicRequestProducer basicRequestProducer = new BasicRequestProducer(httpGet, null);
      asyncClient.execute(basicRequestProducer, new BasicResponseConsumer&lt;&gt;(entityConsumer),
          null, callback);
  </code></pre>
  <p>CallBack2:</p>
  <pre><code>public class Callback2&lt;T&gt; implements FutureCallback&lt;Message&lt;HttpResponse, T&gt;&gt; {
  
  private String message;
  protected CompletableFuture&lt;T&gt; result;
  
  public Callback(CompletableFuture&lt;T&gt; result, String message) {
      this.result = result;
      this.message = message;
  }
  
  @Override
  public void cancelled() {
      result.cancel(true);
  }
  
  @Override
  public void completed(Message&lt;HttpResponse, T&gt; arg0) {
      HttpResponse response = arg0.getHead();
      System.out.println(String.format(message + &quot; completed : http response %s&quot;, response));
      result.complete(arg0.getBody());
  }
  
  @Override
  public void failed(Exception arg0) {
      result.completeExceptionally(arg0);
  }
  </code></pre>
  <p>}</p>
  <p>It fails and I have this stacktrace which I don't understand:</p>
  <pre><code>java.nio.BufferOverflowException
  at java.base/java.nio.HeapByteBuffer.put(HeapByteBuffer.java:233)
  at org.apache.hc.core5.http2.impl.nio.FrameInputBuffer.put(FrameInputBuffer.java:89)
  at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onInput(AbstractH2StreamMultiplexer.java:437)
  at org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.inputReady(AbstractH2IOEventHandler.java:65)
  at org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.inputReady(ClientH2IOEventHandler.java:39)
  at org.apache.hc.core5.reactor.ssl.SSLIOSession.decryptData(SSLIOSession.java:553)
  at org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:72)
  at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.inputReady(SSLIOSession.java:172)
  at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:131)
  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></pre>
  <p>If I add logs (just add log4j2.xml), I get a different exception:</p>
  <pre><code>        2021-03-01 22:02:16,505 DEBUG [org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-00000003: preparing request execution
      2021-03-01 22:02:16,505 DEBUG [org.apache.hc.client5.http.protocol.RequestAddCookies] Cookie spec selected: strict
      2021-03-01 22:02:16,505 DEBUG [org.apache.hc.client5.http.protocol.RequestAuthCache] Auth cache not set in the context
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-00000003: target auth state: UNCHALLENGED
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-00000003: proxy auth state: UNCHALLENGED
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-00000003: acquiring connection with route {s}-&gt;https://www.example.com:443
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] ex-00000003: acquiring endpoint (5 SECONDS)
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: resolving remote address
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: resolved to [www.example.com/2.23.92.197, www.example.com/2.23.92.194, www.example.com/2a02:26f0:2f00:0:0:0:17d5:630, www.example.com/2a02:26f0:2f00:0:0:0:17d5:649]
      2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: connecting null to www.example.com/2.23.92.197:443 (5 SECONDS)
      2021-03-01 22:02:16,513 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: connected c-0000000002 /192.168.0.33:36526-&gt;www.example.com/2.23.92.197:443
      2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] ex-00000003: acquired endpoint
      2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.impl.async.H2AsyncMainClientExec] ex-00000003: executing GET /xxx/test.txt HTTP/1.1
      2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] c-0000000002: start execution ex-00000003
      2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy] Enabled protocols: [TLSv1.2]
      2021-03-01 22:02:16,515 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy] Enabled cipher suites:[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
      2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy] Secure session established
      2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  negotiated protocol: TLSv1.2
      2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  negotiated cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
      2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  peer principal: CN=xxxx.e.example.net, O=&quot;Foo, Inc.&quot;, L=CA, ST=MA, C=US
      2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  peer alternative names: [a248.e.example.net, *.example.net, *.example-staging.net, *.example.net, *.example-staging.net]
      2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  issuer principal: CN=DigiCert Secure Site ECC CA-1, OU=www.example.com, O=DigiCert Inc, C=US
      2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 &gt;&gt; &quot;PRI * HTTP/2.0[\r][\n]&quot;
      2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 &gt;&gt; &quot;[\r][\n]&quot;
      2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 &gt;&gt; &quot;SM[\r][\n]&quot;
      2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 &gt;&gt; &quot;[\r][\n]&quot;
      2021-03-01 22:02:16,540 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 &gt;&gt; &quot;[0x0][0x0]$[0x4][0x0][0x0][0x0][0x0][0x0][0x0][0x1][0x0][0x0][0x10][0x0][0x0][0x2][0x0][0x0][0x0][0x0][0x0][0x3][0x7f][0xffffffff][0xffffffff][0xffffffff][0x0][0x4][0x0][0x0][0xffffffff][0xffffffff][0x0][0x5][0x0][0x0]@[0x0][0x0][0x6][0x7f][0xffffffff][0xffffffff][0xffffffff]&quot;
      2021-03-01 22:02:16,540 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 &gt;&gt; &quot;[0x0][0x0][0x4][0x8][0x0][0x0][0x0][0x0][0x0][0x7f][0xffffffff][0x0][0x0]&quot;
      2021-03-01 22:02:16,546 DEBUG [org.apache.hc.client5.http.impl.async.H2AsyncMainClientExec] ex-00000003: execution failed: Connection is closed
      2021-03-01 22:02:16,546 DEBUG [org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-00000003: request failed: Connection is closed
      2021-03-01 22:02:16,546 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] c-0000000002: endpoint closed
      XXX failed
      org.apache.hc.core5.http.ConnectionClosedException: Connection is closed
          at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onException(AbstractH2StreamMultiplexer.java:661)
          at org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.exception(AbstractH2IOEventHandler.java:91)
          at org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.exception(ClientH2IOEventHandler.java:39)
          at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.exception(SSLIOSession.java:204)
          at org.apache.hc.core5.reactor.InternalDataChannel.onException(InternalDataChannel.java:169)
          at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:55)
          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></pre>
  <p>So:</p>
  <ol>
  <li>Why just adding logging changes things, I guess it's related to speed</li>
  <li>What is the meaning of first exception ?</li>
  <li>How can I fix it ?</li>
  </ol>