#10226 only release the buffer when it could not be propagated to a Content.Source reader
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
499816f79c
commit
8b3db91174
|
@ -1146,7 +1146,10 @@ public class HttpConnection extends AbstractConnection implements Runnable, Writ
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,11 @@ import java.net.URI;
|
|||
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;
|
||||
|
@ -27,9 +30,13 @@ 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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -55,7 +63,8 @@ public class HttpServerTestFixture
|
|||
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
|
||||
|
@ -70,9 +79,20 @@ public class HttpServerTestFixture
|
|||
@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
|
||||
|
|
Loading…
Reference in New Issue