From 33634f22b9eae9ea6a4c0a8360bbcfbea0cdf051 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 28 Jan 2021 22:15:33 -0500 Subject: [PATCH] Do not crash when no StatsD listener running StatsD sends should not block the process from working. Since it's a UDP send I'm not completely sure how it even can fail, but at least when the target is localhost it can and indeed did, making dev somewhat annoying. This just swallows any exceptions produced by the StatsD.push action. --- Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Main.hs b/Main.hs index 2bd2a5b..094da64 100644 --- a/Main.hs +++ b/Main.hs @@ -1028,12 +1028,12 @@ participantJid payloads = elementChildren =<< isNamed (fromString "{http://jabber.org/protocol/muc#user}x") =<< payloads -component db redis statsd backendHost did adhocBotIQReceiver adhocBotMessage toRoomPresences toRejoinManager toJoinPartDebouncer toComponent toStanzaProcessor processDirectMessageRouteConfig jingleHandler componentJid registrationJids conferenceServers = do +component db redis pushStatsd backendHost did adhocBotIQReceiver adhocBotMessage toRoomPresences toRejoinManager toJoinPartDebouncer toComponent toStanzaProcessor processDirectMessageRouteConfig jingleHandler componentJid registrationJids conferenceServers = do sendThread <- forkXMPP $ forever $ flip catchError (log "component EXCEPTION") $ do stanza <- liftIO $ atomically $ readTChan toComponent let tags = maybe "" (";domain=" ++) (textToString . strDomain . jidDomain <$> stanzaTo stanza) - liftIO $ StatsD.push statsd [StatsD.stat ["stanzas", "out" ++ tags] 1 "c" Nothing] + pushStatsd [StatsD.stat ["stanzas", "out" ++ tags] 1 "c" Nothing] case (stanzaFrom stanza, stanzaTo stanza) of (Just from, Just to) @@ -1054,7 +1054,7 @@ component db redis statsd backendHost did adhocBotIQReceiver adhocBotMessage toR flip catchError (\e -> liftIO (log "component part 2 EXCEPTION" e >> killThread sendThread >> killThread recvThread)) $ forever $ do stanza <- atomicUIO $ readTChan toStanzaProcessor let tags = maybe "" (";domain=" ++) (textToString . strDomain . jidDomain <$> stanzaFrom (receivedStanza stanza)) - liftIO $ StatsD.push statsd [StatsD.stat ["stanzas", "in" ++ tags] 1 "c" Nothing] + pushStatsd [StatsD.stat ["stanzas", "in" ++ tags] 1 "c" Nothing] liftIO $ forkIO $ case stanza of (ReceivedPresence p@(Presence { presenceType = PresenceAvailable, presenceFrom = Just from, presenceTo = Just to })) | Just returnFrom <- parseJID (bareTxt to ++ s"/capsQuery") -> @@ -1964,5 +1964,5 @@ main = do (log "runComponent ENDED" <=< (runExceptT . syncIO)) $ runComponent (Server componentJid host (PortNumber port)) secret - (component db redis statsd backendHost did adhocBotIQReceiver (writeTChan adhocBotMessages) toRoomPresences toRejoinManager toJoinPartDebouncer sendToComponent toStanzaProcessor processDirectMessageRouteConfig jingleHandler componentJid [registrationJid] conferences) + (component db redis (void . UIO.fromIO . StatsD.push statsd) backendHost did adhocBotIQReceiver (writeTChan adhocBotMessages) toRoomPresences toRejoinManager toJoinPartDebouncer sendToComponent toStanzaProcessor processDirectMessageRouteConfig jingleHandler componentJid [registrationJid] conferences) _ -> log "ERROR" "Bad arguments" -- 2.45.2