Skip to content

Recover from REFUSED_STREAM errors in HTTP/2.#2571

Merged
swankjesse merged 1 commit into
masterfrom
jwilson.0521.recover_from_refused_stream
May 25, 2016
Merged

Recover from REFUSED_STREAM errors in HTTP/2.#2571
swankjesse merged 1 commit into
masterfrom
jwilson.0521.recover_from_refused_stream

Conversation

@swankjesse

Copy link
Copy Markdown
Collaborator

This implements the following policy:

  • If a REFUSED_STREAM error is received, OkHttp will retry the same stream
    on the same socket 1x.
  • If any other error is received, or an additional REFUSED_STREAM error is
    received, OkHttp will retry on a different route if one exists.

We may want to follow up by going through HTTP/2 error codes and deciding
a per-code retry policy, but this should be good enough for now.

Closes: #2543

return recover(e, routeException, requestBodyOut);
}

private boolean isRecoverable(IOException e, boolean routeException) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This code is just moved)

@swankjesse swankjesse force-pushed the jwilson.0521.recover_from_refused_stream branch from 71c7a9d to 51326d2 Compare May 21, 2016 18:28
server.enqueue(new MockResponse()
.setBody("abc"));

Call call = client.newCall(new Request.Builder()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you use the SingleInetAddressDns here? I was testing with nginx 1.9.15 and I noticed the refuse stream stack trace. I think it's because I was using the IP address directly, but still investigating.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You saw something I didn’t see! I turned that on and of course the test started to fail. I fixed it by changing hasMoreRoutes() to return true if the current route is still valid.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, gotcha. I couldn't get those tests to run in intellij, but just got it working by upgrading my JDK version.

@swankjesse swankjesse force-pushed the jwilson.0521.recover_from_refused_stream branch from 51326d2 to bf0c639 Compare May 22, 2016 01:37
@dave-r12

Copy link
Copy Markdown
Collaborator

Nice, OkHttp can now persevere in yet another hostile scenario. The only thing I had left in my notes - if we wanted this to work with nginx 1.9.15 specifically, I believe we'll need to flush the header frames. Right now, when OkHttp tries to write the data frames, it blocks indefinitely because the window size is 0. The header frames are buffered, so never get sent to nginx and we never receive a window update. See https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/internal/framed/FramedConnection.java#L278

I'll defer to Jake.

return http2ErrorCode;
}

public MockResponse setHttp2ErrorCode(int http2ErrorCode) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"FramedErrorCode"?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+Javadoc explaining that this is used only for SocketPolicy. RESET_STREAM_AT_START

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is defined by HTTP/2. Definitely needs doc. Added.

@JakeWharton

Copy link
Copy Markdown
Collaborator

only minor nits, lgtm

This implements the following policy:

 - If a REFUSED_STREAM error is received, OkHttp will retry the same stream
   on the same socket 1x.
 - If any other error is received, or an additional REFUSED_STREAM error is
   received, OkHttp will retry on a different route if one exists.

We may want to follow up by going through HTTP/2 error codes and deciding
a per-code retry policy, but this should be good enough for now.

Closes: #2543
@swankjesse swankjesse force-pushed the jwilson.0521.recover_from_refused_stream branch from bf0c639 to c9290b7 Compare May 25, 2016 01:40
@swankjesse swankjesse merged commit acbd4e4 into master May 25, 2016
@swankjesse swankjesse deleted the jwilson.0521.recover_from_refused_stream branch July 9, 2016 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants