From 90d1e1e8f108cbffdca0b8b9865fd887a916716d Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Tue, 10 Dec 2024 19:30:14 -0600 Subject: [PATCH 1/2] ref: Adapt to jicoco changes. --- jicofo-common/pom.xml | 4 -- .../org/jitsi/jicofo/xmpp/XmppProvider.kt | 60 ++++++++++++------- jicofo-selector/pom.xml | 4 -- jicofo/pom.xml | 2 +- .../src/main/java/org/jitsi/jicofo/Main.java | 12 ++-- .../jitsi/jicofo/mock/TestColibri2Server.kt | 17 +++++- pom.xml | 6 +- 7 files changed, 64 insertions(+), 41 deletions(-) diff --git a/jicofo-common/pom.xml b/jicofo-common/pom.xml index 32253ea364..e8e8df68c2 100644 --- a/jicofo-common/pom.xml +++ b/jicofo-common/pom.xml @@ -39,10 +39,6 @@ compile - - ${project.groupId} - jicoco - ${project.groupId} jicoco-config diff --git a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt index 5180e3bb16..5e7f961dc0 100644 --- a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt +++ b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt @@ -23,12 +23,8 @@ import org.jitsi.jicofo.metrics.GlobalMetrics import org.jitsi.jicofo.xmpp.XmppProvider.RoomExistsException import org.jitsi.jicofo.xmpp.muc.ChatRoom import org.jitsi.jicofo.xmpp.muc.ChatRoomImpl -import org.jitsi.retry.RetryStrategy -import org.jitsi.retry.SimpleRetryTask import org.jitsi.utils.logging2.Logger import org.jitsi.utils.logging2.createChildLogger -import org.jitsi.xmpp.TrustAllHostnameVerifier -import org.jitsi.xmpp.TrustAllX509TrustManager import org.jivesoftware.smack.AbstractXMPPConnection import org.jivesoftware.smack.ConnectionConfiguration import org.jivesoftware.smack.ConnectionListener @@ -43,9 +39,13 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager import org.jxmpp.jid.DomainBareJid import org.jxmpp.jid.EntityBareJid import org.jxmpp.jid.EntityFullJid +import java.security.cert.X509Certificate import java.util.concurrent.CopyOnWriteArraySet +import java.util.concurrent.ScheduledFuture +import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicBoolean import java.util.logging.Level +import javax.net.ssl.X509TrustManager /** Wraps a Smack [XMPPConnection]. */ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) { @@ -53,8 +53,10 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) { addContext("xmpp_connection", config.name) } - /** We need a retry strategy for the first connect attempt. Later those are handled by Smack internally. */ - private val connectRetry = RetryStrategy(TaskPools.scheduledPool) + /** A task which will keep trying to connect to the XMPP server at a fixed 1-second delay. Smack's + * ReconnectionManager only kicks in once a connection suceeds. */ + private var connectTask: ScheduledFuture<*>? = null + private val connectSyncRoot = Any() /** A list of all listeners registered with this instance. */ private val listeners = CopyOnWriteArraySet() @@ -94,17 +96,34 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) { if (xmppConnection.isConnected) { xmppConnection.disconnect() - // If there was an error reconnecting, do not give up, let's retry - // if we retry too quickly and prosody is not fully up ('invalid-namespace' error) - connectRetry.runRetryingTask( - SimpleRetryTask(0, 1000L, true) { - doConnect() - } - ) + // In some after cases with Stream Management Smack's ReconnectionManager gives up. Make sure we keep + // trying. + scheduleConnectTask() } } } + /** Start/restart the connect task. */ + private fun scheduleConnectTask() = synchronized(connectSyncRoot) { + val delay = 1L + connectTask?.cancel(true) + connectTask = TaskPools.scheduledPool.scheduleAtFixedRate({ + try { + if (doConnect()) { + logger.warn("Failed to connect, will re-try after $delay second") + } else { + logger.info("Connected.") + synchronized(connectSyncRoot) { + connectTask?.cancel(false) + connectTask = null + } + } + } catch (e: Exception) { + logger.error("Failed to connect: ${e.message}, will re-try after $delay second", e) + } + }, 0, delay, TimeUnit.SECONDS) + } + private val connectionListener = object : ConnectionListener { override fun authenticated(connection: XMPPConnection?, resumed: Boolean) { registered = true @@ -145,11 +164,7 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) { if (!started.compareAndSet(false, true)) { logger.info("Already started.") } else { - connectRetry.runRetryingTask( - SimpleRetryTask(0, 5000L, true) { - this.doConnect() - } - ) + scheduleConnectTask() } } @@ -158,7 +173,6 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) { logger.info("Already stopped or not started.") } else { synchronized(this) { - connectRetry.cancel() xmppConnection.disconnect() logger.info("Disconnected.") xmppConnection.removeConnectionListener(connectionListener) @@ -327,8 +341,12 @@ private fun createXmppConnection(config: XmppConnectionConfig, logger: Logger): } if (config.disableCertificateVerification) { logger.warn("Disabling TLS certificate verification!") - setCustomX509TrustManager(TrustAllX509TrustManager()) - setHostnameVerifier(TrustAllHostnameVerifier()) + setCustomX509TrustManager(object : X509TrustManager { + override fun checkClientTrusted(chain: Array?, authType: String?) {} + override fun checkServerTrusted(chain: Array?, authType: String?) {} + override fun getAcceptedIssuers(): Array = emptyArray() + }) + setHostnameVerifier { _, _ -> true } } } diff --git a/jicofo-selector/pom.xml b/jicofo-selector/pom.xml index 3fcef25e26..027c916813 100644 --- a/jicofo-selector/pom.xml +++ b/jicofo-selector/pom.xml @@ -44,10 +44,6 @@ compile - - ${project.groupId} - jicoco - ${project.groupId} jicoco-config diff --git a/jicofo/pom.xml b/jicofo/pom.xml index e2296720cf..0164a56d86 100644 --- a/jicofo/pom.xml +++ b/jicofo/pom.xml @@ -84,7 +84,7 @@ ${project.groupId} - jicoco + jicoco-health-checker ${project.groupId} diff --git a/jicofo/src/main/java/org/jitsi/jicofo/Main.java b/jicofo/src/main/java/org/jitsi/jicofo/Main.java index c1c15dcea6..52907502bf 100644 --- a/jicofo/src/main/java/org/jitsi/jicofo/Main.java +++ b/jicofo/src/main/java/org/jitsi/jicofo/Main.java @@ -19,13 +19,13 @@ import kotlin.jvm.functions.*; import org.jetbrains.annotations.*; -import org.jitsi.cmd.*; import org.jitsi.config.*; import org.jitsi.metaconfig.*; -import org.jitsi.shutdown.*; import org.jitsi.utils.*; import org.jitsi.utils.logging2.*; +import java.util.concurrent.*; + /** * Provides the main entry point of Jitsi Meet conference focus. @@ -42,7 +42,6 @@ public class Main * @param args command-line arguments. */ public static void main(String[] args) - throws ParseException { logger.info("Starting Jicofo."); @@ -63,9 +62,8 @@ public static void main(String[] args) ConfigUtils.PASSWORD_CMD_LINE_ARGS = "user_password"; - ShutdownServiceImpl shutdownService = new ShutdownServiceImpl(); - // Register shutdown hook to perform cleanup before exit - Runtime.getRuntime().addShutdownHook(new Thread(shutdownService::beginShutdown)); + CountDownLatch shutdownLatch = new CountDownLatch(1); + Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown)); JicofoServices jicofoServices; try @@ -88,7 +86,7 @@ public static void main(String[] args) try { - shutdownService.waitForShutdown(); + shutdownLatch.await(); } catch (Exception e) { diff --git a/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/TestColibri2Server.kt b/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/TestColibri2Server.kt index 652667ae6f..5de8188c45 100644 --- a/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/TestColibri2Server.kt +++ b/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/TestColibri2Server.kt @@ -30,7 +30,7 @@ import org.jitsi.xmpp.extensions.colibri2.Sources import org.jitsi.xmpp.extensions.colibri2.Transport import org.jitsi.xmpp.extensions.jingle.DtlsFingerprintPacketExtension import org.jitsi.xmpp.extensions.jingle.IceUdpTransportPacketExtension -import org.jitsi.xmpp.util.createError +import org.jivesoftware.smack.packet.ExtensionElement import org.jivesoftware.smack.packet.IQ import org.jivesoftware.smack.packet.StanzaError import org.jivesoftware.smack.packet.StanzaError.Condition.bad_request @@ -211,3 +211,18 @@ private fun buildFeedbackSources(localAudioSsrc: Long, localVideoSsrc: Long): So .build() ) }.build() + +fun createError( + request: IQ, + errorCondition: StanzaError.Condition, + errorMessage: String? = null, + extension: ExtensionElement? = null +): IQ { + val error = StanzaError.getBuilder(errorCondition) + errorMessage?.let { error.setDescriptiveEnText(it) } + extension?.let { + error.setExtensions(listOf(it)) + } + + return IQ.createErrorResponse(request, error.build()) +} diff --git a/pom.xml b/pom.xml index 1199187059..844eb3cf4c 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ 5.7.2 1.7.32 1.0-127-g6c65524 - 1.1-143-g175c44b + 1.1-SNAPSHOT 3.0.0 4.8.6 4.8.6.6 @@ -144,12 +144,12 @@ ${project.groupId} - jicoco + jicoco-config ${jicoco.version} ${project.groupId} - jicoco-config + jicoco-health-checker ${jicoco.version} From 5e6d723f8c4cdb7c72c7428a5f790fd3a4208515 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Wed, 11 Dec 2024 11:19:24 -0600 Subject: [PATCH 2/2] chore: Update jicoco. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 844eb3cf4c..3d0adcb028 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ 5.7.2 1.7.32 1.0-127-g6c65524 - 1.1-SNAPSHOT + 1.1-150-g57913c0 3.0.0 4.8.6 4.8.6.6