Try to start Tor multiple times at the program start.
MODIFY
WalletWasabi.Fluent/Global.cs
WalletWasabi.Fluent/Global.cs
@@ -221,14 +221,14 @@ public class Global
}
}
- private async Task StartTorProcessManagerAsync(CancellationToken cancel)
+ private async Task StartTorProcessManagerAsync(CancellationToken cancellationToken)
{
if (Config.UseTor && Network != Network.RegTest)
{
using (BenchmarkLogger.Measure(operationName: "TorProcessManager.Start"))
{
TorManager = new TorProcessManager(TorSettings);
- await TorManager.StartAsync(cancel).ConfigureAwait(false);
+ await TorManager.StartAsync(attempts: 3, cancellationToken).ConfigureAwait(false);
Logger.LogInfo($"{nameof(TorProcessManager)} is initialized.");
}

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -51,17 +51,39 @@ public class TorProcessManager : IAsyncDisposable
/// <remarks>Guarded by <see cref="StateLock"/>.</remarks>
private TorControlClient? TorControlClient { get; set; }
+ /// <inheritdoc cref="StartAsync(int, CancellationToken)"/>
+ public Task<(CancellationToken, TorControlClient)> StartAsync(CancellationToken cancellationToken = default)
+ {
+ return StartAsync(attempts: 1, cancellationToken);
+ }
+
/// <summary>Starts loop which makes sure that Tor process is started.</summary>
/// <param name="cancellationToken">Application lifetime cancellation token.</param>
/// <returns>Cancellation token which is canceled once Tor process terminates (either forcefully or gracefully).</returns>
/// <remarks>This method must be called exactly once.</remarks>
- /// <exception cref="OperationCanceledException"/>
- public async Task<(CancellationToken, TorControlClient)> StartAsync(CancellationToken cancellationToken = default)
+ /// <exception cref="OperationCanceledException">When all attempts are tried.</exception>
+ public async Task<(CancellationToken, TorControlClient)> StartAsync(int attempts, CancellationToken cancellationToken = default)
{
LoopTask = RestartingLoopAsync(cancellationToken);
+ for (int i = 0; i < attempts; i++)
+ {
+ try
+ {
+ Logger.LogDebug($"Attempt #{i} to start Tor.");
return await WaitForNextAttemptAsync(cancellationToken).ConfigureAwait(false);
}
+ catch (OperationCanceledException)
+ {
+ if (cancellationToken.IsCancellationRequested)
+ {
+ throw;
+ }
+ }
+ }
+
+ throw new OperationCanceledException("No attempt to start Tor was successful.");
+ }
/// <summary>Waits until Tor process is fully started or until it is stopped for some reason.</summary>
/// <returns>Cancellation token which is canceled once Tor process terminates or once <paramref name="cancellationToken"/> is canceled.</returns>

Try to start Tor multiple times at the program start.