public Task <HttpResponseMessage> Retry() { // If we send the same request again, then Mono (at least) will think it is already sent // and somehow get confused with the old one that is already finished sending. This leads // to blocking until the request finally times out. The same seems to apply if the content // is the same as well var initial = _request.Content == null?Task.FromResult <byte[]>(null) : _request.Content.ReadAsByteArrayAsync(); var newRequest = new HttpRequestMessage(_request.Method, _request.RequestUri); return(initial.ContinueWith(t => { if (t.Result != null) { newRequest.Content = new ByteArrayContent(t.Result); foreach (var header in _request.Content.Headers) { newRequest.Content.Headers.TryAddWithoutValidation(header.Key, header.Value); } } foreach (var header in _request.Headers) { newRequest.Headers.TryAddWithoutValidation(header.Key, header.Value); } foreach (var property in _request.Properties) { newRequest.Properties[property.Key] = property.Value; } newRequest.Version = _request.Version; _request.Dispose(); _request = newRequest; Log.To.Sync.V(Tag, "{0} returned {1} for the next delay ({2} attempts remaining)", _strategy.GetType().Name, _strategy.NextDelay(false), _strategy.RetriesRemaining - 1); return Task .Delay(_strategy.NextDelay(true)) .ContinueWith(t1 => Send(newRequest, this)) .Unwrap(); }).Unwrap()); }
public TimeSpan GetSleepTime() { return(_retryStrategy.NextDelay(false)); }