Skip to content

Commit

Permalink
fix: don't retry all exceptions in http handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed May 29, 2024
1 parent 0501c79 commit c97d939
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions cachix/src/Cachix/Client/Retry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,6 @@ retryAllWithPolicy policy f =
-- Retry everything else
allHandler _ = Handler $ \(_ :: SomeException) -> return True

-- Catches all exceptions except async exceptions with logging support
retryAllWithLogging ::
(MonadIO m, MonadMask m) =>
RetryPolicyM m ->
(Bool -> SomeException -> RetryStatus -> m ()) ->
m a ->
m a
retryAllWithLogging policy logger f =
recovering policy handlers $
const (rethrowLinkedThreadExceptions f)
where
handlers = skipAsyncExceptions ++ [exitCodeHandler, loggingHandler]

-- Skip over exitSuccess/exitFailure
exitCodeHandler _ = Handler $ \(_ :: ExitCode) -> return False

-- Log and retry everything else
loggingHandler = logRetries (return . isSyncException) logger

-- | Unwrap 'Async.ExceptionInLinkedThread' exceptions and rethrow the inner exception.
rethrowLinkedThreadExceptions :: (MonadCatch m) => m a -> m a
rethrowLinkedThreadExceptions =
Expand All @@ -107,13 +88,12 @@ retryHttpWith policy = recoveringDynamic policy handlers . const
where
handlers :: [RetryStatus -> Handler m RetryAction]
handlers =
skipAsyncExceptions' ++ [retryHttpExceptions, retryClientExceptions, retrySyncExceptions]
skipAsyncExceptions' ++ [retryHttpExceptions, retryClientExceptions]

skipAsyncExceptions' = map (fmap toRetryAction .) skipAsyncExceptions

retryHttpExceptions _ = Handler httpExceptionToRetryAction
retryClientExceptions _ = Handler clientExceptionToRetryAction
retrySyncExceptions _ = Handler $ \(_ :: SomeException) -> return ConsultPolicy

httpExceptionToRetryAction :: HTTP.HttpException -> m RetryAction
httpExceptionToRetryAction (HTTP.HttpExceptionRequest _ (HTTP.StatusCodeException response _))
Expand Down

0 comments on commit c97d939

Please sign in to comment.