4 ms·
Sleeping on error is a valid pattern when combined with retries. Consider if that would be a long-starting external process that sets up the listener (or even a
by drdaeman 3y ago
Sleeping on error is a valid pattern when combined with retries. Consider if that would be a long-starting external process that sets up the listener (or even a remote server spinning up). I.e. something we have no control over and that has no ability to signal us it's ready. In such case, sleeping a little then trying to connect (and repeating) would be simple, effective and economical solution.
- mindcrime 3y agoSleeping on error is a valid pattern when combined with retries. Agreed. Just note that it can sometimes (often?) be a good idea to add a small stochastic element to the sleep time, and/or do something similar to the exponential back-off[1] approach that Ethernet (among other things) uses. [1]: https://en.wikipedia.org/wiki/Exponential_backoff https://en.wikipedia.org/wiki/Exponential_backoff
- tylerhou 3y agoYou ideally want both exponential back off plus some random delay (to prevent thundering herd).
- chrsig 3y agoI've never personaly seen any benefit from exponential backoff... constant backoff + jitters + short timeouts has always worked well for me. If anything, people underestimating the ramp up of exponential back off(or not capping it) has left me waiting much longer than necessary
- justcool393 3y agothe amount of times something (Discord is the first example that comes to mind) starts waiting 30 seconds between retries because I wasn't connected to the network has been super absurd.
- hayley-patton 3y agoThat was "more sophisticated" and I was given a sample script without a loop. (I got Terraform to wait in a retry loop, which was apparently too complex.)
- xena 3y agoYeah for the record I'm not talking about delay loops, I'm talking about hardcoded sleeps in test code that cause random failures when unspoken invariants change. DevOps is a unique blend of hellfire that is almost unfair to compare to everything else in the industry. I'm glad I don't work in DevOps anymore.