Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public void succeeded()
@Override
public void failed(Throwable x)
{
close();
getEndPoint().close(x);
Promise<?> promise = (Promise<?>)context.get(org.eclipse.jetty.client.Connection.PROMISE_CONTEXT_KEY);
promise.failed(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
import javax.net.ssl.SSLEngine;

import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.Promise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -129,6 +131,18 @@ private void replaceConnection()
}
}

@Override
public boolean onIdleExpired(TimeoutException timeout)
{
getEndPoint().close(timeout);

@SuppressWarnings("unchecked")
Promise<Connection> promise = (Promise<Connection>)context.get(ClientConnector.CONNECTION_PROMISE_CONTEXT_KEY);
promise.failed(timeout);

return false;
}

@Override
public void close()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

package org.eclipse.jetty.test.client.transport;

import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;

import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
Expand Down Expand Up @@ -62,6 +66,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.eclipse.jetty.client.ProxyProtocolClientConnectionFactory.V1;
Expand Down Expand Up @@ -780,4 +785,41 @@ public void testClientOnlySpeaksHTTP1WithExplicitHTTP2Request() throws Exception

assertThat(failure.getCause(), instanceOf(HttpRequestException.class));
}

@ParameterizedTest
@CsvSource(textBlock = """
http, h1
http, h2
http, h1;h2
https, h1
https, h2
https, h1;h2
""")
public void testServerDoesNotAcceptConnections(String scheme, String protocols) throws Exception
{
try (ServerSocketChannel server = ServerSocketChannel.open())
{
// Bind but do not call accept().
server.bind(new InetSocketAddress("0.0.0.0", 0));
int port = ((InetSocketAddress)server.getLocalAddress()).getPort();

ClientConnector clientConnector = new ClientConnector();
List<ClientConnectionFactory.Info> infos = new ArrayList<>();
for (String protocol : protocols.split(";"))
{
if ("h1".equals(protocol))
infos.add(HttpClientConnectionFactory.HTTP11);
if ("h2".equals(protocol))
{
HTTP2Client http2Client = new HTTP2Client(clientConnector);
ClientConnectionFactory.Info http2 = new ClientConnectionFactoryOverHTTP2.HTTP2(http2Client);
infos.add(http2);
}
}
startClient(clientConnector, infos.toArray(ClientConnectionFactory.Info[]::new));
client.setIdleTimeout(1000);

assertThrows(TimeoutException.class, () -> client.GET(scheme + "://localhost:" + port));
}
}
}