Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Monitoring Connections for Error Status Messages #6283

Closed
wants to merge 1 commit into from

Conversation

bessbd
Copy link

@bessbd bessbd commented Sep 28, 2020

As per https://tools.ietf.org/html/rfc2616#section-8.2.2 An
HTTP/1.1 (or later) client sending a message-body SHOULD
monitor the network connection for an error status while it
is transmitting the request.

Currently, okhttp implements a send request, then read response
if/when request was sent successfully.
This hides early responses such as 413 Payload Too Large
errors from clients.

This commit fixes that by adding a response read in case of an
exception happening while the request is being sent.

This closes #1001 .

Related PR: #6121

As per https://tools.ietf.org/html/rfc2616#section-8.2.2 An
HTTP/1.1 (or later) client sending a message-body SHOULD
monitor the network connection for an error status while it
is transmitting the request.

Currently, okhttp implements a send request, then read response
if/when request was sent successfully.
This hides early responses such as 413 Payload Too Large
errors from clients.

This commit fixes that by adding a response read in case of an
exception happening while the request is being sent.

This closes square#1001 .
Copy link
Collaborator

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

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

We might fix this, but this isn’t the right fix.

import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;

import com.sun.net.httpserver.HttpExchange;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ew

@swankjesse
Copy link
Collaborator

....in particular, we need tests to confirm the connection is properly released and not re-used. Also, we use MockWebServer in this project!

@bessbd
Copy link
Author

bessbd commented Sep 28, 2020

Hi @swankjesse ,

Thank you for the quick response! Can you please elaborate on

but this isn’t the right fix

? Is there something fundamentally off with it or is it more of a "let's use MockWebServer and please add 1-2 more test cases"?

@swankjesse
Copy link
Collaborator

I think the fix needs to move from CallServerInterceptor to ExchangeCodec. If we’re gonna do this, we should support HTTP/1 and HTTP/2 and make sure we leave the connections and streams in a healthy state.

@yschimke
Copy link
Collaborator

@swankjesse Devil's advocate, since it doesn't introduce new API, just improves behaviour in a readable way for HTTP/1.1 should we adopt this short term until a proper full fix covering HTTP/2 also?

@swankjesse
Copy link
Collaborator

I've run into an HTTP/2 variant of this problem and I'm going to attempt to fix that there. The thing I'm least comfortable with is lifecycle of the connection after we recover. It's broken for writing but not reading, and that isn't something we've modeled.

@swankjesse
Copy link
Collaborator

Thanks for driving the work on this. I’ve created a PR that includes some ideas from this. Please review!
#6295

@yschimke yschimke closed this Oct 2, 2020
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.

Handling of early 403 FORBIDDEN with Connection: close whilst streaming
3 participants