Skip to content

Commit 56ffe55

Browse files
authored
Modify pipelining handlers to require full requests (#31280)
Currently the http pipelining handlers seem to support chunked http content. However, this does not make sense. There is a content aggregator in the pipeline before the pipelining handler. This means the pipelining handler should only see full http messages. Additionally, the request handler immediately after the pipelining handler only supports full messages. This commit modifies both nio and netty4 pipelining handlers to assert that an inbound message is a full http message. Additionally it removes the tests for chunked content.
1 parent 0bfd18c commit 56ffe55

File tree

4 files changed

+10
-84
lines changed

4 files changed

+10
-84
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.netty.channel.ChannelDuplexHandler;
2323
import io.netty.channel.ChannelHandlerContext;
2424
import io.netty.channel.ChannelPromise;
25-
import io.netty.handler.codec.http.LastHttpContent;
25+
import io.netty.handler.codec.http.FullHttpRequest;
2626
import org.apache.logging.log4j.Logger;
2727
import org.elasticsearch.common.collect.Tuple;
2828
import org.elasticsearch.http.HttpPipelinedRequest;
@@ -53,17 +53,14 @@ public Netty4HttpPipeliningHandler(Logger logger, final int maxEventsHeld) {
5353

5454
@Override
5555
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
56-
if (msg instanceof LastHttpContent) {
57-
HttpPipelinedRequest<LastHttpContent> pipelinedRequest = aggregator.read(((LastHttpContent) msg));
58-
ctx.fireChannelRead(pipelinedRequest);
59-
} else {
60-
ctx.fireChannelRead(msg);
61-
}
56+
assert msg instanceof FullHttpRequest : "Invalid message type: " + msg.getClass();
57+
HttpPipelinedRequest<FullHttpRequest> pipelinedRequest = aggregator.read(((FullHttpRequest) msg));
58+
ctx.fireChannelRead(pipelinedRequest);
6259
}
6360

6461
@Override
6562
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
66-
assert msg instanceof Netty4HttpResponse : "Message must be type: " + Netty4HttpResponse.class;
63+
assert msg instanceof Netty4HttpResponse : "Invalid message type: " + msg.getClass();;
6764
Netty4HttpResponse response = (Netty4HttpResponse) msg;
6865
boolean success = false;
6966
try {

modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpPipeliningHandlerTests.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -148,38 +148,6 @@ public void testThatPipeliningWorksWhenSlowRequestsInDifferentOrder() throws Int
148148
assertTrue(embeddedChannel.isOpen());
149149
}
150150

151-
public void testThatPipeliningWorksWithChunkedRequests() throws InterruptedException {
152-
final int numberOfRequests = randomIntBetween(2, 128);
153-
final EmbeddedChannel embeddedChannel =
154-
new EmbeddedChannel(
155-
new AggregateUrisAndHeadersHandler(),
156-
new Netty4HttpPipeliningHandler(logger, numberOfRequests),
157-
new WorkEmulatorHandler());
158-
159-
for (int i = 0; i < numberOfRequests; i++) {
160-
final DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/" + i);
161-
embeddedChannel.writeInbound(request);
162-
embeddedChannel.writeInbound(LastHttpContent.EMPTY_LAST_CONTENT);
163-
}
164-
165-
final List<CountDownLatch> latches = new ArrayList<>();
166-
for (int i = numberOfRequests - 1; i >= 0; i--) {
167-
latches.add(finishRequest(Integer.toString(i)));
168-
}
169-
170-
for (final CountDownLatch latch : latches) {
171-
latch.await();
172-
}
173-
174-
embeddedChannel.flush();
175-
176-
for (int i = 0; i < numberOfRequests; i++) {
177-
assertReadHttpMessageHasContent(embeddedChannel, Integer.toString(i));
178-
}
179-
180-
assertTrue(embeddedChannel.isOpen());
181-
}
182-
183151
public void testThatPipeliningClosesConnectionWithTooManyEvents() throws InterruptedException {
184152
final int numberOfRequests = randomIntBetween(2, 128);
185153
final EmbeddedChannel embeddedChannel = new EmbeddedChannel(new Netty4HttpPipeliningHandler(logger, numberOfRequests),

plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpPipeliningHandler.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import io.netty.channel.ChannelDuplexHandler;
2323
import io.netty.channel.ChannelHandlerContext;
2424
import io.netty.channel.ChannelPromise;
25-
import io.netty.handler.codec.http.LastHttpContent;
25+
import io.netty.handler.codec.http.FullHttpRequest;
2626
import org.apache.logging.log4j.Logger;
2727
import org.elasticsearch.common.collect.Tuple;
2828
import org.elasticsearch.http.HttpPipelinedRequest;
2929
import org.elasticsearch.http.HttpPipeliningAggregator;
30-
import org.elasticsearch.http.nio.NettyListener;
31-
import org.elasticsearch.http.nio.NioHttpResponse;
3230

3331
import java.nio.channels.ClosedChannelException;
3432
import java.util.List;
@@ -55,17 +53,14 @@ public NioHttpPipeliningHandler(Logger logger, final int maxEventsHeld) {
5553

5654
@Override
5755
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
58-
if (msg instanceof LastHttpContent) {
59-
HttpPipelinedRequest<LastHttpContent> pipelinedRequest = aggregator.read(((LastHttpContent) msg));
60-
ctx.fireChannelRead(pipelinedRequest);
61-
} else {
62-
ctx.fireChannelRead(msg);
63-
}
56+
assert msg instanceof FullHttpRequest : "Invalid message type: " + msg.getClass();
57+
HttpPipelinedRequest<FullHttpRequest> pipelinedRequest = aggregator.read(((FullHttpRequest) msg));
58+
ctx.fireChannelRead(pipelinedRequest);
6459
}
6560

6661
@Override
6762
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
68-
assert msg instanceof NioHttpResponse : "Message must be type: " + NioHttpResponse.class;
63+
assert msg instanceof NioHttpResponse : "Invalid message type: " + msg.getClass();
6964
NioHttpResponse response = (NioHttpResponse) msg;
7065
boolean success = false;
7166
try {

plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/NioHttpPipeliningHandlerTests.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
import io.netty.channel.embedded.EmbeddedChannel;
2929
import io.netty.handler.codec.http.DefaultFullHttpRequest;
3030
import io.netty.handler.codec.http.DefaultFullHttpResponse;
31-
import io.netty.handler.codec.http.DefaultHttpRequest;
3231
import io.netty.handler.codec.http.FullHttpRequest;
3332
import io.netty.handler.codec.http.FullHttpResponse;
3433
import io.netty.handler.codec.http.HttpMethod;
3534
import io.netty.handler.codec.http.HttpRequest;
36-
import io.netty.handler.codec.http.HttpVersion;
3735
import io.netty.handler.codec.http.LastHttpContent;
3836
import io.netty.handler.codec.http.QueryStringDecoder;
3937
import org.elasticsearch.common.Randomness;
@@ -147,38 +145,6 @@ public void testThatPipeliningWorksWhenSlowRequestsInDifferentOrder() throws Int
147145
assertTrue(embeddedChannel.isOpen());
148146
}
149147

150-
public void testThatPipeliningWorksWithChunkedRequests() throws InterruptedException {
151-
final int numberOfRequests = randomIntBetween(2, 128);
152-
final EmbeddedChannel embeddedChannel =
153-
new EmbeddedChannel(
154-
new AggregateUrisAndHeadersHandler(),
155-
new NioHttpPipeliningHandler(logger, numberOfRequests),
156-
new WorkEmulatorHandler());
157-
158-
for (int i = 0; i < numberOfRequests; i++) {
159-
final DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/" + i);
160-
embeddedChannel.writeInbound(request);
161-
embeddedChannel.writeInbound(LastHttpContent.EMPTY_LAST_CONTENT);
162-
}
163-
164-
final List<CountDownLatch> latches = new ArrayList<>();
165-
for (int i = numberOfRequests - 1; i >= 0; i--) {
166-
latches.add(finishRequest(Integer.toString(i)));
167-
}
168-
169-
for (final CountDownLatch latch : latches) {
170-
latch.await();
171-
}
172-
173-
embeddedChannel.flush();
174-
175-
for (int i = 0; i < numberOfRequests; i++) {
176-
assertReadHttpMessageHasContent(embeddedChannel, Integer.toString(i));
177-
}
178-
179-
assertTrue(embeddedChannel.isOpen());
180-
}
181-
182148
public void testThatPipeliningClosesConnectionWithTooManyEvents() throws InterruptedException {
183149
final int numberOfRequests = randomIntBetween(2, 128);
184150
final EmbeddedChannel embeddedChannel = new EmbeddedChannel(new NioHttpPipeliningHandler(logger, numberOfRequests),

0 commit comments

Comments
 (0)