Skip to content

Commit

Permalink
Client: don't retry Close requests
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Jan 26, 2024
1 parent a6e5182 commit c72daf0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Network/WebSockets/Typed/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module Network.WebSockets.Typed.Client
)
where

import Control.Exception (finally)
import Control.Exception (Exception (fromException), SomeException, finally)
import Control.Monad (when)
import Data.Foldable (for_)
import Data.ByteString (ByteString)
import Data.ByteString.Char8 (unpack)
import Data.Foldable (for_)
import Data.Maybe (isJust)
import Network.WebSockets qualified as WS
import Network.WebSockets.Connection.PingPong qualified as PingPong
Expand Down Expand Up @@ -51,7 +51,7 @@ defaultOptions =
run :: (Session.Codec send, Session.Codec receive) => ByteString -> Options -> Session.Session IO send receive () -> (receive -> Session.Session IO send receive ()) -> IO ()
run uriBS options app receiveApp = do
(isSecure, host, port, path) <- Utils.parseURI uriBS
Stamina.retry (staminaSettings options) $ \retryStatus -> do
Stamina.retryFor (staminaSettings options) handler $ \retryStatus -> do
when (isJust $ Stamina.lastException retryStatus) $
onStaminaRetry options retryStatus
if isSecure
Expand All @@ -61,6 +61,12 @@ run uriBS options app receiveApp = do
connectionOptions :: WS.ConnectionOptions
connectionOptions = WS.defaultConnectionOptions

handler :: SomeException -> IO Stamina.RetryAction
handler exc = case fromException exc of
-- we don't want to retry on close requests
Just WS.CloseRequest {} -> pure Stamina.RaiseException
_ -> pure Stamina.Retry

go :: Stamina.RetryStatus -> WS.ClientApp ()
go retryStatus connection = do
Stamina.resetInitial retryStatus
Expand Down

0 comments on commit c72daf0

Please sign in to comment.