Skip to content

Commit b749dd3

Browse files
committed
requested reads in validator
1 parent a89fec2 commit b749dd3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpHeaderValidator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Netty4HttpHeaderValidator extends ChannelDuplexHandler {
2929
private final ThreadContext threadContext;
3030
private boolean droppingContent;
3131
private boolean validatingRequest;
32+
private boolean readRequested;
3233

3334
public Netty4HttpHeaderValidator(HttpValidator validator, ThreadContext threadContext) {
3435
this.validator = validator;
@@ -47,6 +48,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
4748
} else if (msg instanceof HttpContent content) {
4849
if (droppingContent) {
4950
content.release();
51+
ctx.read();
5052
} else {
5153
assert validatingRequest == false : "unexpected content before validation completed";
5254
ctx.fireChannelRead(content);
@@ -60,7 +62,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
6062
public void read(ChannelHandlerContext ctx) throws Exception {
6163
// until validation is completed we can ignore read calls,
6264
// once validation is finished HttpRequest will be fired and downstream can read from there
63-
if (validatingRequest == false) {
65+
if (validatingRequest) {
66+
readRequested = true;
67+
} else {
68+
readRequested = false;
6469
ctx.read();
6570
}
6671
}
@@ -108,6 +113,10 @@ void handleValidationResult(ChannelHandlerContext ctx, HttpRequest request, @Nul
108113
}
109114
validatingRequest = false;
110115
ctx.fireChannelRead(request);
116+
if (readRequested) {
117+
readRequested = false;
118+
ctx.channel().eventLoop().execute(ctx::read);
119+
}
111120
});
112121
}
113122

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpPipeliningHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
146146
}
147147
}
148148
handlePipelinedRequest(ctx, netty4HttpRequest);
149-
if (request instanceof FullHttpRequest) {
150-
ctx.read();
151-
}
152149
} else {
153150
assert msg instanceof HttpContent : "expect HttpContent got " + msg;
154151
assert currentRequestStream != null : "current stream must exists before handling http content";
@@ -158,6 +155,11 @@ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
158155
}
159156
}
160157
} finally {
158+
if (msg instanceof HttpRequest httpRequest) {
159+
if (httpRequest instanceof FullHttpRequest || httpRequest.decoderResult().isFailure()) {
160+
ctx.channel().eventLoop().execute(ctx::read);
161+
}
162+
}
161163
activityTracker.stopActivity();
162164
}
163165
}

0 commit comments

Comments
 (0)