add retry + delay in case of unresponsive API provider
MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -113,7 +113,6 @@ public class Global : IDisposable
}
HttpClient.BaseAddress = url;
- HttpClient.Timeout = TimeSpan.FromMinutes(2);
var coinVerifierApiClient = new CoinVerifierApiClient(CoordinatorParameters.RuntimeCoordinatorConfig.CoinVerifierApiAuthToken, RpcClient.Network, HttpClient);
var whitelist = await Whitelist.CreateAndLoadFromFileAsync(CoordinatorParameters.WhitelistFilePath, wabiSabiConfig, cancel).ConfigureAwait(false);

MODIFY
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifierApiClient.cs
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifierApiClient.cs
@@ -48,6 +48,7 @@ public class CoinVerifierApiClient
using CancellationTokenSource linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token);
int tries = 3;
+ var delay = TimeSpan.FromSeconds(2);
HttpResponseMessage? response = null;
@@ -58,28 +59,36 @@ public class CoinVerifierApiClient
using var content = new HttpRequestMessage(HttpMethod.Get, $"{HttpClient.BaseAddress}{address}");
content.Headers.Authorization = new("Bearer", ApiToken);
+ try
+ {
response = await HttpClient.SendAsync(content, linkedTokenSource.Token).ConfigureAwait(false);
- if (response.StatusCode == HttpStatusCode.OK)
+ if (response is { } && response.StatusCode == HttpStatusCode.OK)
{
// Successful request, break the iteration.
break;
}
else
{
- Logger.LogWarning($"API request failed. {nameof(HttpStatusCode)} was {response.StatusCode}.");
+ Logger.LogWarning($"API request failed. {nameof(HttpStatusCode)} was {response?.StatusCode}.");
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError($"API request failed for script: {script}. Remaining tries: {tries}.", ex);
+ await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
}
}
while (tries > 0);
// Throw proper exceptions - if needed - according to the latest response.
- if (response.StatusCode == HttpStatusCode.Forbidden)
+ if (response?.StatusCode == HttpStatusCode.Forbidden)
{
throw new UnauthorizedAccessException("User roles access forbidden.");
}
- else if (response.StatusCode != HttpStatusCode.OK)
+ else if (response?.StatusCode != HttpStatusCode.OK)
{
- throw new InvalidOperationException($"API request failed. {nameof(HttpStatusCode)} was {response.StatusCode}.");
+ throw new InvalidOperationException($"API request failed. {nameof(HttpStatusCode)} was {response?.StatusCode}.");
}
string responseString = await response.Content.ReadAsStringAsync(linkedTokenSource.Token).ConfigureAwait(false);

add retry + delay in case of unresponsive API provider