Merged branch 'jetty-9.2.x' into 'jetty-9.3.x'.

This commit is contained in:
Simone Bordet 2016-03-01 15:21:19 +01:00
commit 04bb4af12c
2 changed files with 31 additions and 0 deletions

View File

@ -152,6 +152,9 @@ public abstract class PoolingHttpDestination<C extends Connection> extends HttpD
{
if (LOG.isDebugEnabled())
LOG.debug("Aborted before processing {}: {}", exchange, cause);
// Won't use this connection, release it back.
if (!connectionPool.release(connection))
connection.close();
// It may happen that the request is aborted before the exchange
// is created. Aborting the exchange a second time will result in
// a no-operation, so we just abort here to cover that edge case.

View File

@ -25,6 +25,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -47,6 +48,33 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
super(sslContextFactory);
}
@Test
public void testAbortBeforeQueued() throws Exception
{
start(new EmptyServerHandler());
Exception failure = new Exception("oops");
try
{
Request request = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.timeout(5, TimeUnit.SECONDS);
request.abort(failure);
request.send();
Assert.fail();
}
catch (ExecutionException x)
{
Assert.assertSame(failure, x.getCause());
// Make sure the pool is in a sane state.
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP)client.getDestination(scheme, "localhost", connector.getLocalPort());
ConnectionPool connectionPool = destination.getConnectionPool();
Assert.assertEquals(1, connectionPool.getConnectionCount());
Assert.assertEquals(0, connectionPool.getActiveConnections().size());
Assert.assertEquals(1, connectionPool.getIdleConnections().size());
}
}
@Test
public void testAbortOnQueued() throws Exception
{