Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8194910

HttpClient throw protocol error or EOFException during downloading multiple files only when h2c

    Details

      Description

      The following test fails frequently
      import static jdk.incubator.http.HttpClient.Version.HTTP_2;

      import java.net.URI;
      import java.nio.file.Paths;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.concurrent.CompletableFuture;
      import java.util.concurrent.atomic.AtomicLong;
      import java.util.regex.Matcher;
      import java.util.regex.Pattern;

      import org.testng.annotations.BeforeClass;
      import org.testng.annotations.Test;

      import jdk.incubator.http.HttpClient;
      import jdk.incubator.http.HttpClient.Builder;
      import jdk.incubator.http.HttpClient.Version;
      import jdk.incubator.http.HttpRequest;
      import jdk.incubator.http.HttpResponse;

      /*
       * @test
       * @run testng/othervm TestMultiFiles
       */
      public class TestMultiFiles {// -Djdk.internal.httpclient.debug=true
          private static final List<String> datafileList = new ArrayList<>();

          private static final String dataDir = "http://&lt;host&gt;:8080/yc/data/";


          @BeforeClass
          public void getFileList() throws Exception {
              HttpClient client = getClient(HTTP_2);
              HttpResponse<String> resp = client.send(
                      HttpRequest.newBuilder(new URI(dataDir)).GET().build(),
                      HttpResponse.BodyHandler.asString());

              Matcher m = Pattern.compile("<a href=\"(.+).data\">").matcher(resp.body());
              while (m.find()) {
                  datafileList.add(m.group(1) + ".data");
              }
              
              System.out.println(datafileList);
          }

          @Test
          public void test() throws Exception {
              test(HTTP_2);
          }

          private static HttpClient getClient(Version v) {
              return HttpClient.newBuilder().proxy(Builder.NO_PROXY).version(v).build();
          }

          private void test(Version v) throws Exception {
              HttpClient client = getClient(v);

              int taskIndex = 0;
              CompletableFuture[] results = new CompletableFuture[datafileList.size()];
              
              for (String datafileName : datafileList)
                  results[taskIndex++] = client
                          .sendAsync(
                                  HttpRequest.newBuilder(new URI(dataDir + datafileName)).GET().build(),
                                  HttpResponse.BodyHandler.asFile(Paths.get(datafileName)))
                          .thenApply(resp -> {
                              System.out.println(resp.body());
                              return true;
                          });

              CompletableFuture.allOf(results).join();
          }
      }

      with protocol error, e.g.
      java.util.concurrent.CompletionException: java.io.IOException: protocol error: Frame type(83) length(5537666) exceeds MAX_FRAME_SIZE(16384)
      at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:331)
      at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:346)
      at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:870)
      at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
      at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
      at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.MinimalFuture.complete(MinimalFuture.java:171)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.MinimalFuture.lambda$of$2(MinimalFuture.java:163)
      at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
      at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
      at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
      at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
      at jdk.incubator.httpclient/jdk.incubator.http.ResponseSubscribers$PathSubscriber.onError(ResponseSubscribers.java:161)
      at jdk.incubator.httpclient/jdk.incubator.http.Stream.schedule(Stream.java:194)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:271)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:224)
      at jdk.incubator.httpclient/jdk.incubator.http.Stream.cancelImpl(Stream.java:922)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.shutdown(Http2Connection.java:555)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.protocolError(Http2Connection.java:733)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.processFrame(Http2Connection.java:574)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.frame.FramesDecoder.decode(FramesDecoder.java:156)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection$FramesController.processReceivedData(Http2Connection.java:195)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.asyncReceive(Http2Connection.java:528)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection$Http2TubeSubscriber.processQueue(Http2Connection.java:1036)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      at java.base/java.lang.Thread.run(Thread.java:844)

      or EOFException
      java.util.concurrent.CompletionException: java.io.EOFException: EOF reached while reading
      at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:331)
      at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:346)
      at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:870)
      at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
      at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
      at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.MinimalFuture.complete(MinimalFuture.java:171)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.MinimalFuture.lambda$of$2(MinimalFuture.java:163)
      at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
      at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
      at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
      at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
      at jdk.incubator.httpclient/jdk.incubator.http.ResponseSubscribers$PathSubscriber.onError(ResponseSubscribers.java:161)
      at jdk.incubator.httpclient/jdk.incubator.http.Stream.schedule(Stream.java:194)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:271)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:224)
      at jdk.incubator.httpclient/jdk.incubator.http.Stream.cancelImpl(Stream.java:922)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.shutdown(Http2Connection.java:555)
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection$Http2TubeSubscriber.processQueue(Http2Connection.java:1046)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      at java.base/java.lang.Thread.run(Thread.java:844)
      Caused by: java.io.EOFException: EOF reached while reading
      at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection$Http2TubeSubscriber.onComplete(Http2Connection.java:1087)
      at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:551)
      at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:728)
      at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$SocketFlowTask.run(SocketTube.java:171)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:271)
      at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:224)
      at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:675)
      at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:829)
      at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:243)
      at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:769)
      at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:731)

        Attachments

          Activity

            People

            • Assignee:
              chegar Chris Hegarty
              Reporter:
              fyuan Frank Yuan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: