Skip to content

Commit

Permalink
#10226 only release the buffer when it could not be propagated to a C…
Browse files Browse the repository at this point in the history
…ontent.Source reader

Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Aug 29, 2023
1 parent 8263ff5 commit 74ab484
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,10 @@ public Throwable consumeAvailable()
Throwable result = HttpStream.consumeAvailable(this, getHttpConfiguration());
if (result != null)
_generator.setPersistent(false);
releaseRequestBuffer();
// If the parser is not at the end, an idle timeout occurred and nothing
// is ever going to release the buffer -> release it here.
if (!_parser.isState(HttpParser.State.END))
releaseRequestBuffer();
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

import org.awaitility.Awaitility;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.io.ArrayByteBufferPool;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.util.Blocker;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import static org.junit.jupiter.api.Assertions.fail;

// @checkstyle-disable-check : AvoidEscapedUnicodeCharactersCheck
public class HttpServerTestFixture
{
Expand All @@ -38,6 +45,7 @@ public class HttpServerTestFixture

protected QueuedThreadPool _threadPool;
protected Server _server;
protected ArrayByteBufferPool.Tracking _bufferPool;
protected URI _serverURI;
protected HttpConfiguration _httpConfiguration;
protected ServerConnector _connector;
Expand All @@ -55,7 +63,8 @@ protected Socket newSocket(String host, int port) throws Exception
public void before()
{
_threadPool = new QueuedThreadPool();
_server = new Server(_threadPool);
_bufferPool = new ArrayByteBufferPool.Tracking();
_server = new Server(_threadPool, new ScheduledExecutorScheduler(), _bufferPool);
}

protected void initServer(ServerConnector connector) throws Exception
Expand All @@ -70,9 +79,20 @@ protected void initServer(ServerConnector connector) throws Exception
@AfterEach
public void stopServer() throws Exception
{
_server.stop();
_server.join();
_server.setConnectors(new Connector[]{});
try
{
Awaitility.await().atMost(3, TimeUnit.SECONDS).until(() -> _bufferPool.getLeaks().size(), Matchers.is(0));
}
catch (Exception e)
{
fail(e.getMessage() + "\n---\nServer Leaks: " + _bufferPool.dumpLeaks() + "---\n");
}
finally
{
_server.stop();
_server.join();
_server.setConnectors(new Connector[]{});
}
}

protected void startServer(Handler handler) throws Exception
Expand Down

0 comments on commit 74ab484

Please sign in to comment.