What is a GoAway Frame in Http2 and how is it linked to Redirects?
Asked Answered
K

2

8

I am aware of HTTP/2 Client provided by Java 9 and while trying out the incubator module with the following code:

// Request builder
URI uri = new URI("http://www.stackoverflow.com/"); // using www.google.com gives me some payload with no exception
HttpRequest request = HttpRequest.newBuilder().uri(uri).GET().build();

// Client
HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build();
System.out.println(httpClient.version());

// Response builder
HttpResponse response = httpClient.send(request, HttpResponse.BodyHandler.asString());

System.out.println("statusCode = " + response.statusCode()); // 200 for google.com

I received this as an output :

Exception in thread "main" java.io.IOException: /192.168.0.2:60726: GOAWAY received
  at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.handleGoAway(Http2Connection.java:613)
  at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.handleConnectionFrame(Http2Connection.java:531)
  at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.processFrame(Http2Connection.java:466)
  at jdk.incubator.httpclient/jdk.incubator.http.internal.frame.FramesDecoder.decode(FramesDecoder.java:114)
  at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection$FramesController.processReceivedData(Http2Connection.java:152)
  at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.asyncReceive(Http2Connection.java:425)
  at jdk.incubator.httpclient/jdk.incubator.http.AsyncSSLDelegate.upperRead(AsyncSSLDelegate.java:557)
  at jdk.incubator.httpclient/jdk.incubator.http.internal.common.Queue.put(Queue.java:73)
  at jdk.incubator.httpclient/jdk.incubator.http.AsyncSSLDelegate.asyncReceive(AsyncSSLDelegate.java:503)
  at jdk.incubator.httpclient/jdk.incubator.http.PlainHttpConnection.asyncRead(PlainHttpConnection.java:300)
  at jdk.incubator.httpclient/jdk.incubator.http.PlainHttpConnection$ReadEvent.handle(PlainHttpConnection.java:395)
  at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:438)
  at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:408)

Moving down the stack trace I could find GOAWAY listed as one of types of

jdk.incubator.http.internal.frame.Http2Frame

but then the internal class is not much documented to find exactly what does this type represent. I tried searching for the same on links from the JEPs as well, but couldn't find any.

Q. What is a GoAway Frame? When and how is it used?

Q. Why if I change my code to use a client without following redirects trying to GET "stackoverflow.com" I do not get the same exception?

HttpClient httpClient = HttpClient.newBuilder().build();
Kamerad answered 25/9, 2017 at 6:36 Comment(0)
F
11

As set in the specifications,

The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of a connection by a server.

It is likely that the frame is sent by the server on the second connection, the one following the redirect.

Do all URLs at stackoverflow.com accept http/2 connections ? That does not seem to be the case when looking at the indicator of my HTTP/2-SPDY browser plugin.

Functionary answered 25/9, 2017 at 7:3 Comment(4)
Thanks for the doc. Coul you elaborate frame is sent by the server on the second connection why would that not happen at first and when I remove the following redirections does the server not try and redirect(since it results in 200 then)?Kamerad
I was thinking of the following scenario: the first connection happens via http/2 which redirects to a (redirect) URL. The client then tries to access that URL via HTTP/2 however the server responding to requests on that URL does not support HTTP/2 => GOAWAY. If you instruct your http client to not follow redirects, it should never attempt to access the redirect URL (... and I do not understand how you get a 200 in that scenario)Functionary
seems the link is dead. I am getting errorCode in GOAWAY Frame. is there any mapping of error code and description?Lorelle
What about the expression "go away" could be presented as "graceful" ?Orabelle
B
4

Redirect from HTTP/1.1 with Upgrade to HTTP/2 over TLS erroneously includes Upgrade header. This issue has been filed

https://bugs.openjdk.java.net/browse/JDK-8198709

Balliol answered 26/2, 2018 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.