Replace auto-read with proper flow-control in HTTP pipeline#127817
Merged
elasticsearchmachine merged 5 commits intoelastic:mainfrom May 8, 2025
Merged
Conversation
Re-applying elastic#126441 (cf. elastic#127259) with: - the extra `FlowControlHandler` needed to ensure one-chunk-per-read semantics (also present in elastic#127259). - no extra `read()` after exhausting a `Netty4HttpRequestBodyStream` (the bug behind elastic#127391 and elastic#127391). See elastic#127111 for related tests.
Collaborator
|
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
Collaborator
|
Hi @DaveCTurner, I've created a changelog YAML for you. |
Contributor
Author
|
The diff over #127259 is the following: diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestBodyStream.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestBodyStream.java
index b4396569ae35..f7c9d1404c61 100644
--- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestBodyStream.java
+++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestBodyStream.java
@@ -31,6 +31,7 @@ public class Netty4HttpRequestBodyStream implements HttpBody.Stream {
private final ThreadContext threadContext;
private final ChannelHandlerContext ctx;
private boolean closing = false;
+ private boolean readLastChunk = false;
private HttpBody.ChunkHandler handler;
private ThreadContext.StoredContext requestContext;
private final ChannelFutureListener closeListener = future -> doClose();
@@ -49,6 +50,7 @@ public class Netty4HttpRequestBodyStream implements HttpBody.Stream {
@Override
public void setHandler(ChunkHandler chunkHandler) {
+ assert ctx.channel().eventLoop().inEventLoop() : Thread.currentThread().getName();
this.handler = chunkHandler;
}
@@ -70,10 +72,12 @@ public class Netty4HttpRequestBodyStream implements HttpBody.Stream {
}
public void handleNettyContent(HttpContent httpContent) {
+ assert ctx.channel().eventLoop().inEventLoop() : Thread.currentThread().getName();
if (closing) {
httpContent.release();
read();
} else {
+ assert readLastChunk == false;
try (var ignored = threadContext.restoreExistingContext(requestContext)) {
var isLast = httpContent instanceof LastHttpContent;
var buf = Netty4Utils.toReleasableBytesReference(httpContent.content());
@@ -82,8 +86,9 @@ public class Netty4HttpRequestBodyStream implements HttpBody.Stream {
}
handler.onNext(buf, isLast);
if (isLast) {
- read();
+ readLastChunk = true;
ctx.channel().closeFuture().removeListener(closeListener);
+ read();
}
}
}
@@ -99,6 +104,7 @@ public class Netty4HttpRequestBodyStream implements HttpBody.Stream {
}
private void doClose() {
+ assert ctx.channel().eventLoop().inEventLoop() : Thread.currentThread().getName();
closing = true;
try (var ignored = threadContext.restoreExistingContext(requestContext)) {
for (var tracer : tracingHandlers) {
@@ -108,6 +114,8 @@ public class Netty4HttpRequestBodyStream implements HttpBody.Stream {
handler.close();
}
}
- read();
+ if (readLastChunk == false) {
+ read();
+ }
}
}This avoids a spurious extra |
ywangd
pushed a commit
to ywangd/elasticsearch
that referenced
this pull request
May 9, 2025
…127817) Re-applying elastic#126441 (cf. elastic#127259) with: - the extra `FlowControlHandler` needed to ensure one-chunk-per-read semantics (also present in elastic#127259). - no extra `read()` after exhausting a `Netty4HttpRequestBodyStream` (the bug behind elastic#127391 and elastic#127391). See elastic#127111 for related tests.
jfreden
pushed a commit
to jfreden/elasticsearch
that referenced
this pull request
May 12, 2025
…127817) Re-applying elastic#126441 (cf. elastic#127259) with: - the extra `FlowControlHandler` needed to ensure one-chunk-per-read semantics (also present in elastic#127259). - no extra `read()` after exhausting a `Netty4HttpRequestBodyStream` (the bug behind elastic#127391 and elastic#127391). See elastic#127111 for related tests.
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.
Re-applying #126441 (cf. #127259) with:
the extra
FlowControlHandlerneeded to ensure one-chunk-per-readsemantics (also present in Replace auto-read with proper flow-control in HTTP pipeline #127259).
no extra
read()after exhausting aNetty4HttpRequestBodyStream(the bug behind [CI] Netty4IncrementalRequestHandlingIT testHttpClientStats failing #127391 and [CI] Netty4IncrementalRequestHandlingIT testHttpClientStats failing #127391).
See #127111 for related tests.