Skip to content

Commit 3e3673b

Browse files
Fix ByteBuf Leak in Nio HTTP Tests (#51444) (#51457)
It is the job of the http server transport to release the request in the handler but the mock fails to do so since we never override `incomingRequest`.
1 parent fbec19c commit 3e3673b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import static org.mockito.Matchers.any;
7676
import static org.mockito.Matchers.eq;
7777
import static org.mockito.Mockito.atLeastOnce;
78+
import static org.mockito.Mockito.doAnswer;
7879
import static org.mockito.Mockito.mock;
7980
import static org.mockito.Mockito.times;
8081
import static org.mockito.Mockito.verify;
@@ -92,6 +93,10 @@ public class HttpReadWriteHandlerTests extends ESTestCase {
9293
@Before
9394
public void setMocks() {
9495
transport = mock(NioHttpServerTransport.class);
96+
doAnswer(invocation -> {
97+
((HttpRequest) invocation.getArguments()[0]).releaseAndCopy();
98+
return null;
99+
}).when(transport).incomingRequest(any(HttpRequest.class), any(HttpChannel.class));
95100
Settings settings = Settings.builder().put(SETTING_HTTP_MAX_CONTENT_LENGTH.getKey(), new ByteSizeValue(1024)).build();
96101
HttpHandlingSettings httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);
97102
channel = mock(NioHttpChannel.class);

0 commit comments

Comments
 (0)