Skip to content

Commit

Permalink
Fix ByteBuf Leak in Nio HTTP Tests (#51444) (#51457)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
original-brownbear committed Jan 25, 2020
1 parent fbec19c commit 3e3673b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -92,6 +93,10 @@ public class HttpReadWriteHandlerTests extends ESTestCase {
@Before
public void setMocks() {
transport = mock(NioHttpServerTransport.class);
doAnswer(invocation -> {
((HttpRequest) invocation.getArguments()[0]).releaseAndCopy();
return null;
}).when(transport).incomingRequest(any(HttpRequest.class), any(HttpChannel.class));
Settings settings = Settings.builder().put(SETTING_HTTP_MAX_CONTENT_LENGTH.getKey(), new ByteSizeValue(1024)).build();
HttpHandlingSettings httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);
channel = mock(NioHttpChannel.class);
Expand Down

0 comments on commit 3e3673b

Please sign in to comment.