Add http stream content size handler (fixed #120246)#121095
Merged
mhl-b merged 1 commit intoelastic:mainfrom Jan 29, 2025
Merged
Add http stream content size handler (fixed #120246)#121095mhl-b merged 1 commit intoelastic:mainfrom
mhl-b merged 1 commit intoelastic:mainfrom
Conversation
Collaborator
|
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
mhl-b
commented
Jan 28, 2025
Comment on lines
+131
to
+138
| if (isOversized) { | ||
| if (isContinueExpected) { | ||
| // Client is allowed to send content without waiting for Continue. | ||
| // See https://www.rfc-editor.org/rfc/rfc9110.html#section-10.1.1-11.3 | ||
| // this content will result in HttpRequestDecoder failure and send downstream | ||
| decoder.reset(); | ||
| } | ||
| ctx.writeAndFlush(TOO_LARGE.retainedDuplicate()).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); |
Contributor
Author
There was a problem hiding this comment.
The fix. No longer close connection. Previous version:
if (isOversized) {
if (isContinueExpected) {
// Client is allowed to send content without waiting for Continue.
// See https://www.rfc-editor.org/rfc/rfc9110.html#section-10.1.1-11.3
// this content will result in HttpRequestDecoder failure and send downstream
decoder.reset();
ctx.writeAndFlush(TOO_LARGE.retainedDuplicate()).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
} else {
// Client is sending oversized content, we cannot safely take it. Closing channel.
ctx.writeAndFlush(TOO_LARGE_CLOSE.retainedDuplicate()).addListener(ChannelFutureListener.CLOSE);
}
Collaborator
💔 Backport failed
You can use sqren/backport to manually backport by running |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reapplying #120246 with fix after it's being reverted #120934.
Fix. In original PR requests without
Expect: 100-Continueand oversized are rejected with subsequent channel closure. This is not what netty does and introduced breakage on elasticsearch-js client. The expected behaviour is that ES should reject request and discard body without closing connection.Description from original PR.
Netty's HttpObjectAggregator handles for Expect: 100-Continue and chunked oversized requests besides aggregating parts. But HTTP stream handling does not use aggregator and we plan to remove it completely. That means we need to handle these cases by ourself.
This PR introduces Netty4HttpContentSizeHandler that handles expect-continue and oversized requests in the same way as HttpObjectAggregator. Some parts are copied from netty's code and simplified for our usage. Follow up on #117787 split into smaller pieces.
Once we completely switch to HTTP stream this handler will replace HttpObjectAggregator. For now there is conditional logic between stream and aggregation.
There is an interesting interaction between HttpRequestDecoder and HttpObjectAggregator . When aggregator responds with 413-too-large to expect-100-continue it resets HttpRequestDecoder through userEvent in pipeline.
Aggregator sends event and Decoder resets state.
This reset is required to avoid treating subsequent request as content of rejected request. But this is private code. Public interface is HttpRequestDecoder#reset(), so Netty4HttpContentSizeHandler requires explicit access to decoder and reset.