Skip to content

http-netty: stop sending the request body after an error response with Connection: close - #3734

Open
idelpivnitskiy wants to merge 1 commit into
apple:mainfrom
idelpivnitskiy:error-response-stops-body
Open

idelpivnitskiy wants to merge 1 commit into
apple:mainfrom
idelpivnitskiy:error-response-stops-body

Conversation

@idelpivnitskiy

Copy link
Copy Markdown
Member

Motivation

RFC 9112 section 9.5: a client that sees a response indicating the server doesn't want the request body and is closing the connection SHOULD stop sending the body.
The HTTP/1.1 client kept uploading the whole body, e.g. after a late rejection of Expect: 100-continue or an
early 413 to a plain upload. With writes still queued, the closed connection could also fail the response.

Modifications

  • On a final non-2xx response that closes the connection, HttpResponseDecoder stops a request payload body that
    is still being sent. The encoder marks the request complete, so the connection closes after the response.
  • WriteStreamSubscriber.terminateSource() can stop a source that is already writing. The write completes without
    waiting for in-flight writes, so their failure on close doesn't fail the response. A request that wrote nothing
    yet is left alone, so it still fails as retryable, and writes already aborted (pipelined requests) or failed by
    the source keep their failure.
  • Responses without Connection: close don't stop the body: the server may keep reading it.

Result

The client stops uploading once the server rejects the request and closes the connection, and still delivers the
response. Less unread request data on the server also makes a TCP RST less likely when the server closes the
connection non-gracefully after a non-2xx response, which could otherwise cut the response short.

…h Connection: close

#### Motivation

[RFC 9112 section 9.5](https://www.rfc-editor.org/rfc/rfc9112#section-9.5): a client that sees a response
indicating the server doesn't want the request body and is closing the connection SHOULD stop sending the body.
The HTTP/1.1 client kept uploading the whole body, e.g. after a late rejection of `Expect: 100-continue` or an
early `413` to a plain upload. With writes still queued, the closed connection could also fail the response.

#### Modifications

- On a final non-2xx response that closes the connection, `HttpResponseDecoder` stops a request payload body that
  is still being sent. The encoder marks the request complete, so the connection closes after the response.
- `WriteStreamSubscriber.terminateSource()` can stop a source that is already writing. The write completes without
  waiting for in-flight writes, so their failure on close doesn't fail the response. A request that wrote nothing
  yet is left alone, so it still fails as retryable, and writes already aborted (pipelined requests) or failed by
  the source keep their failure.
- Responses without `Connection: close` don't stop the body: the server may keep reading it.

#### Result

The client stops uploading once the server rejects the request and closes the connection, and still delivers the
response. Less unread request data on the server also makes a TCP RST less likely when the server closes the
connection non-gracefully after a non-2xx response, which could otherwise cut the response short.

This branch has not been deployed

No deployments
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.

1 participant