We are trying to implement a retry policy for our database logic when we receive timeout exceptions due to exhausting the connection pool. This happens when we have a spike of unusually large activity for a small period of time. We have increased our max pool size to try to avoid this situation, but we would also like to have the retry logic in place as a backup plan.
The documentation for connection pooling states that:
When connection pooling is enabled, and if a timeout error or other login error occurs, an exception will be thrown and subsequent connection attempts will fail for the next five seconds, the "blocking period". If the application attempts to connect within the blocking period, the first exception will be thrown again. Subsequent failures after a blocking period ends will result in a new blocking periods that is twice as long as the previous blocking period, up to a maximum of one minute.
Polly seems well suited to address this problem, through the PolicyWrap combination of Fallback, WaitAndRetry, and Circuit Breaker policies. There's a good picture of this here
Ideally, I was hoping to be able to specify an exponential durationOfBreak for the Circuit Breaker to match the doubling period described above. I haven't seen any examples online of how this could be possible, so maybe it's not possible?
What is the desired configuration approach here? Is it to specify a Circuit Breaker with a 5 second durationOfBreak and then use an exponential retry for the WaitAndRetry component of 5, 10, 20, 40, and 60 seconds? That seems unfortunate in the case that connections have just become available and your old operation just started its 40 second wait while a new operation would work immediately.
Another possibility is to have a 5 second durationOfBreak and then have the WaitAndRetry component use a very small wait with lots of retries, even though we know many of these retries will fail if they come before the documentation states.
I appreciate your feedback!