Skip to content

Commit

Permalink
[Brig] Clean up a couple of unsafe functions (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimjasevic authored Apr 22, 2022
1 parent 3cb643f commit df943c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/brig-fun-cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removes an unused function in Brig and relocates another one
27 changes: 0 additions & 27 deletions services/brig/src/Brig/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ module Brig.App
-- * App Monad
AppT,
runAppT,
runAppResourceT,
fork,
locationOf,
viewFederationDomain,
qualifyLocal,
Expand Down Expand Up @@ -122,7 +120,6 @@ import Data.Default (def)
import Data.Domain
import qualified Data.GeoIP2 as GeoIp
import Data.IP
import Data.Id (UserId)
import qualified Data.List.NonEmpty as NE
import Data.List1 (List1, list1)
import Data.Metrics (Metrics)
Expand Down Expand Up @@ -636,30 +633,6 @@ runAppT e (AppT ma) =
. passwordResetStoreToCodeStore
$ runReaderT ma e

runAppResourceT ::
ResourceT (AppT BrigCanonicalEffects) a ->
(AppT BrigCanonicalEffects) a
runAppResourceT ma = do
e <- ask
liftIO . runResourceT $ transResourceT (runAppT e) ma

fork ::
(MonadIO m, MonadUnliftIO m, MonadReader Env m) =>
Maybe UserId ->
m a ->
m ()
fork u ma = do
g <- view applog
r <- view requestId
let logErr e = Log.err g $ request r ~~ user u ~~ msg (show e)
withRunInIO $ \lower ->
void . liftIO . forkIO $
either logErr (const $ return ())
=<< runExceptT (syncIO $ lower ma)
where
request = field "request" . unRequestId
user = maybe id (field "user" . toByteString)

locationOf :: (MonadIO m, MonadReader Env m) => IP -> m (Maybe Location)
locationOf ip =
view geoDb >>= \case
Expand Down
19 changes: 19 additions & 0 deletions services/brig/src/Brig/IO/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import qualified Brig.User.Search.Index as Search
import Cassandra (MonadClient)
import Conduit (runConduit, (.|))
import Control.Error (ExceptT)
import Control.Error.Util
import Control.Lens (view, (.~), (?~), (^.))
import Control.Monad.Catch
import Control.Monad.Trans.Except (runExceptT, throwE)
Expand Down Expand Up @@ -122,6 +123,7 @@ import Network.HTTP.Types.Method
import Network.HTTP.Types.Status
import qualified Network.Wai.Utilities.Error as Wai
import System.Logger.Class as Log hiding (name, (.=))
import qualified System.Logger.Extended as ExLog
import Wire.API.Federation.API.Brig
import Wire.API.Federation.Error
import Wire.API.Message (UserClients)
Expand Down Expand Up @@ -469,6 +471,23 @@ notify events orig route conn recipients = fork (Just orig) $ do
rs <- recipients
push events rs orig route conn

fork ::
(MonadIO m, MonadUnliftIO m, MonadReader Env m) =>
Maybe UserId ->
m a ->
m ()
fork u ma = do
g <- view applog
r <- view requestId
let logErr e = ExLog.err g $ request r ~~ user u ~~ msg (show e)
withRunInIO $ \lower ->
void . liftIO . forkIO $
either logErr (const $ return ())
=<< runExceptT (syncIO $ lower ma)
where
request = field "request" . unRequestId
user = maybe id (field "user" . toByteString)

notifySelf ::
( MonadIO m,
Log.MonadLogger m,
Expand Down

0 comments on commit df943c4

Please sign in to comment.