Skip to content

Commit d6711e4

Browse files
Tim-Brooksmhl-b
andauthored
Unmute channel when flush last http stream chunk (#113222) (#115862)
Co-authored-by: Mikhail Berezovskiy <[email protected]>
1 parent 573e494 commit d6711e4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ public void handleNettyContent(HttpContent httpContent) {
8787
send();
8888
}
8989
}
90-
if (hasLast) {
91-
channel.config().setAutoRead(true);
92-
channel.closeFuture().removeListener(closeListener);
93-
}
9490
}
9591

9692
// adds chunk to current buffer, will allocate composite buffer when need to hold more than 1 chunk
@@ -133,6 +129,10 @@ private void send() {
133129
tracer.onNext(bytesRef, hasLast);
134130
}
135131
handler.onNext(bytesRef, hasLast);
132+
if (hasLast) {
133+
channel.config().setAutoRead(true);
134+
channel.closeFuture().removeListener(closeListener);
135+
}
136136
}
137137

138138
@Override

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public void testFlushAllReceivedChunks() {
8282
assertEquals(chunkSize * totalChunks, totalBytes.get());
8383
}
8484

85+
// ensures that channel.setAutoRead(true) only when we flush last chunk
86+
public void testSetAutoReadOnLastFlush() {
87+
channel.writeInbound(randomLastContent(10));
88+
assertFalse("should not auto-read on last content reception", channel.config().isAutoRead());
89+
stream.next();
90+
channel.runPendingTasks();
91+
assertTrue("should set auto-read once last content is flushed", channel.config().isAutoRead());
92+
}
93+
8594
// ensures that we read from channel when no current chunks available
8695
// and pass next chunk downstream without holding
8796
public void testReadFromChannel() {

0 commit comments

Comments
 (0)