Skip to content

Commit d290c98

Browse files
NorfairKingdbaynard
authored andcommitted
Changed the default retry strategy (commercialhaskell#4109)
* Changed the default retry strategy This changes makes the default retry strategy an exponential backoff starting from 100 ms. This should counteract the problem that is being tracked in commercialhaskell#3510. This new strategy means that it will take 12.7 seconds for stack to fail entirely when the network cable is unplugged.
1 parent d6dd041 commit d290c98

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Other enhancements:
3232
`build.interleaved-output` config value which causes multiple concurrent
3333
builds to dump to stderr at the same time with a `packagename> ` prefix. See
3434
[#3225](https://github.com/commercialhaskell/stack/issues/3225).
35+
* The default retry strategy has changed to exponential backoff.
36+
This should help with
37+
[#3510](https://github.com/commercialhaskell/stack/issues/3510).
3538

3639
Bug fixes:
3740

src/Network/HTTP/Download/Verified.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import qualified Data.Text.Encoding as Text
3030
import Control.Monad
3131
import Control.Monad.Catch (Handler (..)) -- would be nice if retry exported this itself
3232
import Stack.Prelude hiding (Handler (..))
33-
import Control.Retry (recovering,limitRetries,RetryPolicy,constantDelay,RetryStatus(..))
33+
import Control.Retry (recovering,limitRetries,RetryPolicy,exponentialBackoff,RetryStatus(..))
3434
import Crypto.Hash
3535
import Crypto.Hash.Conduit (sinkHash)
3636
import Data.ByteArray as Mem (convert)
@@ -59,9 +59,20 @@ data DownloadRequest = DownloadRequest
5959
, drRetryPolicy :: RetryPolicy
6060
}
6161

62-
-- | Default to retrying thrice with a short constant delay.
62+
-- | Default to retrying seven times with exponential backoff starting from
63+
-- one hundred milliseconds.
64+
--
65+
-- This means the tries will occur after these delays if necessary:
66+
--
67+
-- * 0.1s
68+
-- * 0.2s
69+
-- * 0.4s
70+
-- * 0.8s
71+
-- * 1.6s
72+
-- * 3.2s
73+
-- * 6.4s
6374
drRetryPolicyDefault :: RetryPolicy
64-
drRetryPolicyDefault = limitRetries 3 <> constantDelay onehundredMilliseconds
75+
drRetryPolicyDefault = limitRetries 7 <> exponentialBackoff onehundredMilliseconds
6576
where onehundredMilliseconds = 100000
6677

6778
data HashCheck = forall a. (Show a, HashAlgorithm a) => HashCheck
@@ -210,6 +221,7 @@ recoveringHttp retryPolicy =
210221
[ "If you see this warning and stack fails to download,"
211222
, "but running the command again solves the problem,"
212223
, "please report here: https://github.com/commercialhaskell/stack/issues/3510"
224+
, "Make sure to paste the output of 'stack --version'"
213225
]
214226
]
215227
return True

0 commit comments

Comments
 (0)