From 76bd88518ac0fb7d4a7589e442a453d8838682aa Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 30 Mar 2020 10:29:57 -0400 Subject: [PATCH] fix freeswitch retry connection logic --- lib/utils/install-srf-locals.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/utils/install-srf-locals.js b/lib/utils/install-srf-locals.js index aa8cd489..44acde9d 100644 --- a/lib/utils/install-srf-locals.js +++ b/lib/utils/install-srf-locals.js @@ -53,8 +53,9 @@ function installSrfLocals(srf, logger) { // retry to connect to any that were initially offline setInterval(async() => { for (const val of mediaservers) { - if (val.connect === 0) { + if (val.connects === 0) { try { + logger.info({mediaserver: val.opts}, 'Retrying initial connection to media server'); const ms = await mrf.connect(val.opts); val.ms = ms; } catch (err) { @@ -66,13 +67,15 @@ function installSrfLocals(srf, logger) { // if we have a single freeswitch (as is typical) report stats periodically if (mediaservers.length === 1) { - const ms = mediaservers[0].ms; setInterval(() => { try { - stats.gauge('fs.media.channels.in_use', ms.currentSessions); - stats.gauge('fs.media.channels.free', ms.maxSessions - ms.currentSessions); - stats.gauge('fs.media.calls_per_second', ms.cps); - stats.gauge('fs.media.cpu_idle', ms.cpuIdle); + if (mediaservers[0].ms && mediaservers[0].active) { + const ms = mediaservers[0].ms; + stats.gauge('fs.media.channels.in_use', ms.currentSessions); + stats.gauge('fs.media.channels.free', ms.maxSessions - ms.currentSessions); + stats.gauge('fs.media.calls_per_second', ms.cps); + stats.gauge('fs.media.cpu_idle', ms.cpuIdle); + } } catch (err) { logger.info(err, 'Error sending media server metrics');