mirror of
https://github.com/apache/activemq.git
synced 2025-02-09 03:25:33 +00:00
AMQ-6698 - Allow timeout of SSL handshake for auto+nio+ssl
The handshake now takes place inside of the async task that timesout so that if the SSL handshake takes too long the connection attempt will honor protocolDetectionTimeout and actually timeout. Also, change the default of protocolDetectionTimeout to 30 seconds so it matches the rest of the broker's default connection timeout settings.
This commit is contained in:
parent
daeb70929e
commit
2a0b785a04
@ -78,7 +78,7 @@ public class AutoTcpTransportServer extends TcpTransportServer {
|
|||||||
protected final ThreadPoolExecutor newConnectionExecutor;
|
protected final ThreadPoolExecutor newConnectionExecutor;
|
||||||
protected final ThreadPoolExecutor protocolDetectionExecutor;
|
protected final ThreadPoolExecutor protocolDetectionExecutor;
|
||||||
protected int maxConnectionThreadPoolSize = Integer.MAX_VALUE;
|
protected int maxConnectionThreadPoolSize = Integer.MAX_VALUE;
|
||||||
protected int protocolDetectionTimeOut = 15000;
|
protected int protocolDetectionTimeOut = 30000;
|
||||||
|
|
||||||
private static final FactoryFinder TRANSPORT_FACTORY_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/transport/");
|
private static final FactoryFinder TRANSPORT_FACTORY_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/transport/");
|
||||||
private final ConcurrentMap<String, TransportFactory> transportFactories = new ConcurrentHashMap<String, TransportFactory>();
|
private final ConcurrentMap<String, TransportFactory> transportFactories = new ConcurrentHashMap<String, TransportFactory>();
|
||||||
|
@ -110,14 +110,18 @@ public class AutoNIOSSLTransportServer extends AutoTcpTransportServer {
|
|||||||
//Clone the map because we will need to set the options later on the actual transport
|
//Clone the map because we will need to set the options later on the actual transport
|
||||||
IntrospectionSupport.setProperties(in, new HashMap<>(transportOptions));
|
IntrospectionSupport.setProperties(in, new HashMap<>(transportOptions));
|
||||||
}
|
}
|
||||||
in.start();
|
|
||||||
SSLEngine engine = in.getSslSession();
|
|
||||||
|
|
||||||
//Attempt to read enough bytes to detect the protocol until the timeout period
|
//Attempt to read enough bytes to detect the protocol until the timeout period
|
||||||
//is reached
|
//is reached
|
||||||
Future<?> future = protocolDetectionExecutor.submit(new Runnable() {
|
Future<?> future = protocolDetectionExecutor.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
|
in.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("Could not complete Transport start", e);
|
||||||
|
}
|
||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
do {
|
do {
|
||||||
if(attempts > 0) {
|
if(attempts > 0) {
|
||||||
@ -157,7 +161,7 @@ public class AutoNIOSSLTransportServer extends AutoTcpTransportServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WireFormat format = protocolInfo.detectedWireFormatFactory.createWireFormat();
|
WireFormat format = protocolInfo.detectedWireFormatFactory.createWireFormat();
|
||||||
Transport transport = createTransport(socket, format, engine, initBuffer, in.getInputBuffer(), protocolInfo.detectedTransportFactory);
|
Transport transport = createTransport(socket, format, in.getSslSession(), initBuffer, in.getInputBuffer(), protocolInfo.detectedTransportFactory);
|
||||||
|
|
||||||
return new TransportInfo(format, transport, protocolInfo.detectedTransportFactory);
|
return new TransportInfo(format, transport, protocolInfo.detectedTransportFactory);
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ public class OpenWireConnectionTimeoutTest {
|
|||||||
case "auto+ssl":
|
case "auto+ssl":
|
||||||
case "nio+ssl":
|
case "nio+ssl":
|
||||||
case "auto+nio+ssl":
|
case "auto+nio+ssl":
|
||||||
useSsl = true;;
|
useSsl = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IOException("Invalid OpenWire connector scheme passed to test.");
|
throw new IOException("Invalid OpenWire connector scheme passed to test.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user