From 880ef47fd5733ee34800788f33f0dc2e12231034 Mon Sep 17 00:00:00 2001 From: Alex Gidman Date: Tue, 18 Jul 2023 13:50:51 +0100 Subject: [PATCH] feat: OF-2559 - surface session initialise timeout to a system property --- i18n/src/main/resources/openfire_i18n.properties | 1 + .../session/LocalOutgoingServerSession.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/i18n/src/main/resources/openfire_i18n.properties b/i18n/src/main/resources/openfire_i18n.properties index 545cd05ea7..5a1589bd2f 100644 --- a/i18n/src/main/resources/openfire_i18n.properties +++ b/i18n/src/main/resources/openfire_i18n.properties @@ -1683,6 +1683,7 @@ system_property.xmpp.server.outgoing.max.threads=Minimum amount of threads in th system_property.xmpp.server.outgoing.min.threads=Maximum amount of threads in the thread pool that is used to establish outbound server-to-server connections system_property.xmpp.server.outgoing.threads-timeout=Amount of time after which idle, surplus threads are removed from the thread pool that is used to establish outbound server-to-server connections. system_property.xmpp.server.outgoing.queue=Maximum amount of outbound server-to-server connections that can be in process of establishment in the thread pool (surplus connections will be created on the calling thread, possibly / gracefully slowing down other operations considerably) +system_property.xmpp.server.session.initialise-timeout=Maximum amount of time in seconds for an outbound S2S session to be initialised system_property.cluster-monitor.service-enabled=Set to true to send messages to admins on cluster events, otherwise false system_property.ldap.override.avatar=Set to true to save avatars in the local database, otherwise false system_property.xmpp.domain=The XMPP domain of this server. Do not change this property directly, instead re-run the setup process. diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalOutgoingServerSession.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalOutgoingServerSession.java index 09d2eaa292..bac652680a 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalOutgoingServerSession.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalOutgoingServerSession.java @@ -26,6 +26,7 @@ import org.jivesoftware.openfire.server.OutgoingServerSocketReader; import org.jivesoftware.openfire.server.RemoteServerManager; import org.jivesoftware.openfire.server.ServerDialback; +import org.jivesoftware.util.SystemProperty; import org.jivesoftware.util.TaskEngine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +35,8 @@ import javax.annotation.Nonnull; import java.net.Socket; import java.net.SocketAddress; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.HashSet; import java.util.Map; @@ -67,6 +70,16 @@ public class LocalOutgoingServerSession extends LocalServerSession implements Ou private static final Interner remoteAuthMutex = Interners.newWeakInterner(); + /** + * Controls the S2S outgoing session initialise timeout time in seconds + */ + public static final SystemProperty INITIALISE_TIMEOUT_SECONDS = SystemProperty.Builder.ofType(Duration.class) + .setKey("xmpp.server.session.initialise-timeout") + .setDefaultValue(Duration.ofSeconds(5)) + .setChronoUnit(ChronoUnit.SECONDS) + .setDynamic(true) + .build(); + private OutgoingServerSocketReader socketReader; private final Collection outgoingDomainPairs = new HashSet<>(); @@ -254,7 +267,7 @@ private static LocalOutgoingServerSession createOutgoingSession(@Nonnull final D // Wait for the future to give us a session... sessionInitialiser = new NettySessionInitializer(domainPair, port, directTLS); // Set a read timeout (of 5 seconds) so we don't keep waiting forever - return (LocalOutgoingServerSession) sessionInitialiser.init().get(5000, TimeUnit.MILLISECONDS); + return (LocalOutgoingServerSession) sessionInitialiser.init().get(INITIALISE_TIMEOUT_SECONDS.getValue().getSeconds(), TimeUnit.SECONDS); } catch (Exception e) {