HTTP / 2和Jetty:超出最大本地流计数100

时间:2016-01-11 09:17:47

标签: java http jetty http2

在使用基本的HTTP / 2 GET请求时,Jetty似乎没有重用它的内部流。在大约100个请求之后,它抛出以下异常:

Caused by: java.lang.IllegalStateException: Max local stream count 100 exceeded
    at org.eclipse.jetty.http2.HTTP2Session.createLocalStream(HTTP2Session.java:614)
    at org.eclipse.jetty.http2.HTTP2Session.newStream(HTTP2Session.java:430)
    at org.eclipse.jetty.http2.client.http.HttpSenderOverHTTP2.sendHeaders(HttpSenderOverHTTP2.java:86)
    at org.eclipse.jetty.client.HttpSender.send(HttpSender.java:204)
    at org.eclipse.jetty.http2.client.http.HttpChannelOverHTTP2.send(HttpChannelOverHTTP2.java:73)
    at org.eclipse.jetty.http2.client.http.HttpConnectionOverHTTP2.send(HttpConnectionOverHTTP2.java:52)
    at org.eclipse.jetty.http2.client.http.HttpDestinationOverHTTP2.send(HttpDestinationOverHTTP2.java:36)
    at org.eclipse.jetty.http2.client.http.HttpDestinationOverHTTP2.send(HttpDestinationOverHTTP2.java:26)
    at org.eclipse.jetty.client.MultiplexHttpDestination.process(MultiplexHttpDestination.java:117)
    at org.eclipse.jetty.client.MultiplexHttpDestination.send(MultiplexHttpDestination.java:59)
    at org.eclipse.jetty.client.HttpDestination.send(HttpDestination.java:199)
    at org.eclipse.jetty.client.HttpClient.send(HttpClient.java:538)
    at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:694)
    at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:647)
    ... 8 more

我使用的代码如下:

HTTP2Client http2Client = new HTTP2Client();
http2Client.start();

HttpClient client = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), ssl);
        client.start();

for (int i = 0; i < 1000; i++) {
    System.out.println(i);
    ContentResponse response = client.GET("https://http2.akamai.com");
    System.out.println("response code: " + response.getStatus());
}

我进一步研究了Jetty的源代码,它为每个请求创建了一个新流。为什么会这样?

我有什么遗失的东西吗? 这使得它几乎无法用于API请求等。

1 个答案:

答案 0 :(得分:1)

您遇到了已修复的错误。

请更新至Jetty 9.3.7.RC0或更高版本。

谢谢!