@@ -30,11 +30,9 @@ module Simplex.Messaging.Notifications.Server.Env
3030import Control.Concurrent (ThreadId )
3131import qualified Control.Exception as E
3232import Control.Logger.Simple
33- import Control.Monad
3433import Control.Monad.Except
3534import Control.Monad.Trans.Except
3635import Crypto.Random
37- import Data.Functor (($>) )
3836import Data.Int (Int64 )
3937import Simplex.Messaging.Agent.RetryInterval
4038import Data.List.NonEmpty (NonEmpty )
@@ -66,7 +64,6 @@ import Simplex.Messaging.Transport.Credentials (genCredentials, tlsCredentials)
6664import Simplex.Messaging.Transport.Server (AddHTTP , ServerCredentials , TransportServerConfig , loadFingerprint , loadServerCredential )
6765import Simplex.Messaging.Util (liftEitherWith , tshow )
6866import Simplex.Messaging.Util ()
69- import System.Exit (exitFailure )
7067import System.Mem.Weak (Weak )
7168import UnliftIO.STM
7269
@@ -177,7 +174,7 @@ data NtfPushServer = NtfPushServer
177174 { pushWorkers :: TMap (Maybe T. Text , PushProvider , Int ) PushWorkerVar , -- Int is the worker shard
178175 pushWorkerSeq :: TVar Int ,
179176 pushQSize :: Natural ,
180- pushClients :: TMap PushProvider PushClientVar ,
177+ pushClients :: TMap ( PushProvider , Int ) PushClientVar ,
181178 pushClientSeq :: TVar Int ,
182179 apnsConfig :: APNSPushClientConfig
183180 }
@@ -203,27 +200,27 @@ newNtfPushServer pushQSize apnsConfig = do
203200-- | Single-flight access to the per-provider push client with bounded retry.
204201-- The returned PushClientVar is the handle retryDeliver passes to removeSessVar to evict
205202-- this specific instance before re-fetching.
206- getPushClient :: NtfPushServer -> PushProvider -> IO (PushProviderClient , PushClientVar )
207- getPushClient s@ NtfPushServer {apnsConfig = APNSPushClientConfig {reconnectInterval}} pp =
203+ getPushClient :: NtfPushServer -> PushProvider -> Int -> IO (PushProviderClient , PushClientVar )
204+ getPushClient s@ NtfPushServer {apnsConfig = APNSPushClientConfig {reconnectInterval}} pp tokenShardId =
208205 withRetryIntervalCount reconnectInterval $ \ n _delay loop -> do
209206 ts <- getCurrentTime
210- E. try (atomically (getSessVar (pushClientSeq s) pp (pushClients s) ts) >>= either (newPushClient s pp) waitForPushClient) >>= \ case
207+ E. try (atomically (getSessVar (pushClientSeq s) (pp, tokenShardId) (pushClients s) ts) >>= either (newPushClient s pp tokenShardId ) waitForPushClient) >>= \ case
211208 Right result -> pure result
212209 Left e
213210 | n < 2 -> do
214211 logError $ " getPushClient error (" <> tshow pp <> " ): " <> tshow (e :: E. SomeException )
215212 loop
216213 | otherwise -> E. throwIO e
217214
218- newPushClient :: NtfPushServer -> PushProvider -> PushClientVar -> IO (PushProviderClient , PushClientVar )
219- newPushClient NtfPushServer {pushClients, apnsConfig} pp v = do
215+ newPushClient :: NtfPushServer -> PushProvider -> Int -> PushClientVar -> IO (PushProviderClient , PushClientVar )
216+ newPushClient NtfPushServer {pushClients, apnsConfig} pp tokenShardId v = do
220217 r <- E. try $ case apnsProviderHost pp of
221218 Nothing -> pure $ \ _ _ -> pure ()
222219 Just host -> apnsPushProviderClient <$> createAPNSPushClient host apnsConfig
223220 atomically $ do
224221 putTMVar (sessionVar v) r
225222 case r of
226- Left _ -> removeSessVar v pp pushClients
223+ Left _ -> removeSessVar v (pp, tokenShardId) pushClients
227224 Right _ -> pure ()
228225 either E. throwIO (\ c -> pure (c, v)) r
229226
0 commit comments