From 7c8c142694fbf803a952a5264e0aeb2b2ae1b56c Mon Sep 17 00:00:00 2001 From: sh Date: Fri, 15 May 2026 12:48:39 +0000 Subject: [PATCH] ntf-server: carry retry reason in PPRetryLater, log retries Change PPRetryLater from nullary to PPRetryLater Text so the cause (503 / 410-reason) propagates to the retry call site. Log a warning at every retry attempt with provider, token id and reason. --- src/Simplex/Messaging/Notifications/Server.hs | 9 +++++---- src/Simplex/Messaging/Notifications/Server/Push/APNS.hs | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Simplex/Messaging/Notifications/Server.hs b/src/Simplex/Messaging/Notifications/Server.hs index a508b2a17..681bd3c22 100644 --- a/src/Simplex/Messaging/Notifications/Server.hs +++ b/src/Simplex/Messaging/Notifications/Server.hs @@ -672,8 +672,8 @@ ntfPush s@NtfPushServer {pushQ} = forever $ do runExceptT (deliver tkn ntf) >>= \case Right _ -> pure $ Right () Left e -> case e of - PPConnection _ -> retryDeliver - PPRetryLater -> retryDeliver + PPConnection ce -> retryDeliver $ "connection " <> tshow ce + PPRetryLater r -> retryDeliver r PPCryptoError _ -> err e PPResponseError {} -> err e PPTokenInvalid r -> do @@ -681,8 +681,9 @@ ntfPush s@NtfPushServer {pushQ} = forever $ do err e PPPermanentError -> err e where - retryDeliver :: IO (Either PushProviderError ()) - retryDeliver = do + retryDeliver :: Text -> IO (Either PushProviderError ()) + retryDeliver reason = do + logWarn $ "retrying push (" <> tshow pp <> ", " <> tshow ntfTknId <> "): " <> reason deliver <- newPushClient s pp runExceptT (deliver tkn ntf) >>= \case Right _ -> pure $ Right () diff --git a/src/Simplex/Messaging/Notifications/Server/Push/APNS.hs b/src/Simplex/Messaging/Notifications/Server/Push/APNS.hs index 4b274271c..2c5f3bac1 100644 --- a/src/Simplex/Messaging/Notifications/Server/Push/APNS.hs +++ b/src/Simplex/Messaging/Notifications/Server/Push/APNS.hs @@ -326,7 +326,7 @@ data PushProviderError | PPCryptoError C.CryptoError | PPResponseError (Maybe Status) Text | PPTokenInvalid NTInvalidReason - | PPRetryLater + | PPRetryLater Text | PPPermanentError deriving (Show, Exception) @@ -373,8 +373,8 @@ apnsPushProviderClient c@APNSPushClient {nonceDrg, apnsCfg} tkn@NtfTknRec {token | status == Just N.gone410 = throwE $ case reason' of "ExpiredToken" -> PPTokenInvalid NTIRExpiredToken "Unregistered" -> PPTokenInvalid NTIRUnregistered - _ -> PPRetryLater - | status == Just N.serviceUnavailable503 = liftIO (disconnectApnsHTTP2Client c) >> throwE PPRetryLater + _ -> PPRetryLater $ "410 " <> reason' + | status == Just N.serviceUnavailable503 = liftIO (disconnectApnsHTTP2Client c) >> throwE (PPRetryLater "503") -- Just tooManyRequests429 -> TooManyRequests - too many requests for the same token | otherwise = throwE $ PPResponseError status reason' liftHTTPS2 a = ExceptT $ first PPConnection <$> a