HTTP/2 和 Jetty:超过最大本地流计数 100
HTTP/2 and Jetty: Max local stream count 100 exceeded
在使用基本的 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 请求等
您遇到了一个已修复的错误。
请更新至 Jetty 9.3.7.RC0 或更高版本。
谢谢!
在使用基本的 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 请求等
您遇到了一个已修复的错误。
请更新至 Jetty 9.3.7.RC0 或更高版本。
谢谢!