question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExponentialRetryPolicy materializes GetIntervals()

See original GitHub issue

The constructor of ExponentialRetryPolicy materializes the IEnumerable<TimeSpan> returned from GetIntervals(). This seems directly opposed to its nature:

  • It is an iterator function.
  • It treats Int32.MaxValue as unlimited.

When using retryLimit: Int32.MaxValue, which GetIntervals() explicitly special-cases, the loop is infinite (until ToArray() tries to allocate an array that is too large).

Even when avoiding Int32.MaxValue, when trying to accommodate a very large number of attempts, the materialized array can take a lot of memory, when the intervals could just be calculated on-the-fly. Materialization also incurs a lot of calls to Random.Next() that would otherwise have been amortized over the lifetime of the policy instance.

A good alternative property type to TimeSpan[] might be IEnumerator<TimeSpan>, since it enforces forward-only behavior. It is a public property, unfortunately, so I’m not sure how far the impact reaches.

I ran into this issue when I was trying to use exponential message retries in MassTransit 7.0.7.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
phatboygcommented, Aug 17, 2021

FYI, I finally got around to cleaning this up a bit.

0reactions
phatboygcommented, Aug 18, 2021

No worries, appreciate the concern to recheck the logic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ExponentialRetryPolicy (AWS SDK for Java - 1.12.529)
Stop retrying after the specified interval. void, validate(). Performs the following three validation checks for ExponentialRetry Policy: 1) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found