Skip to content

Commit f8d7fb1

Browse files
committed
intercept readComplete
1 parent 3be681b commit f8d7fb1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

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

3433
public Netty4HttpHeaderValidator(HttpValidator validator, ThreadContext threadContext) {
3534
this.validator = validator;
@@ -62,14 +61,18 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
6261
public void read(ChannelHandlerContext ctx) throws Exception {
6362
// until validation is completed we can ignore read calls,
6463
// once validation is finished HttpRequest will be fired and downstream can read from there
65-
if (validatingRequest) {
66-
readRequested = true;
67-
} else {
68-
readRequested = false;
64+
if (validatingRequest == false) {
6965
ctx.read();
7066
}
7167
}
7268

69+
@Override
70+
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
71+
if (validatingRequest == false) {
72+
ctx.fireChannelReadComplete();
73+
}
74+
}
75+
7376
void validate(ChannelHandlerContext ctx, HttpRequest request) {
7477
assert Transports.assertDefaultThreadContext(threadContext);
7578
droppingContent = false;
@@ -113,10 +116,7 @@ void handleValidationResult(ChannelHandlerContext ctx, HttpRequest request, @Nul
113116
}
114117
validatingRequest = false;
115118
ctx.fireChannelRead(request);
116-
if (readRequested) {
117-
readRequested = false;
118-
ctx.channel().eventLoop().execute(ctx::read);
119-
}
119+
ctx.fireChannelReadComplete();
120120
});
121121
}
122122

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ protected HttpMessage createMessage(String[] initialLine) throws Exception {
366366
decoder.setCumulator(ByteToMessageDecoder.COMPOSITE_CUMULATOR);
367367
ch.pipeline().addLast("decoder", decoder); // parses the HTTP bytes request into HTTP message pieces
368368
ch.pipeline().addLast(new FlowControlHandler());
369+
ch.config().setAutoRead(false);
370+
ch.read();
369371
if (httpValidator != null) {
370372
// runs a validation function on the first HTTP message piece which contains all the headers
371373
// if validation passes, the pieces of that particular request are forwarded, otherwise they are discarded
@@ -423,8 +425,6 @@ protected Result beginEncode(HttpResponse httpResponse, String acceptEncoding) t
423425
new Netty4HttpPipeliningHandler(transport.pipeliningMaxEvents, transport, threadWatchdogActivityTracker)
424426
);
425427
transport.serverAcceptedChannel(nettyHttpChannel);
426-
ch.config().setAutoRead(false);
427-
ch.read();
428428
}
429429

430430
@Override

0 commit comments

Comments
 (0)