Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

Sync Polly with timeout

$
0
0

This code runs to the end, no TimeoutRejectedException.If I change the strategy to TimeoutStrategy.Pessimistic, it will enter the executed logic twice, before throwing the TimeoutRejectedException.

What should I do, if I want to retry after a timeout with the retry policy? (if it does a timeout, I want to try again after a pause until I hit MaxRetries)?

Is the only solution to make my executing logic itself throw the timeout?(The code is .net framework 4.8 and it made to run in LinqPad 5 and Polly v 8.3.1).

The Optimistic strategy does not seem to actually do anything in this setup, does it?

var retry = Policy    .Handle<Exception>()    .Retry(1);var timeout = Policy    .Timeout(1, Polly.Timeout.TimeoutStrategy.Optimistic);var wrap = Policy.Wrap(retry, timeout);try{    wrap        .Execute(() =>        {"Enter executed logic".Dump();            Thread.Sleep(5000);"Exit executed logic".Dump();        });}catch(TimeoutRejectedException ex){    ex.Message.Dump();}

Viewing all articles
Browse latest Browse all 950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>