Remove TorSocks5Client.IsConnected and make it more easy to follow the code.
MODIFY
WalletWasabi/Tor/Http/TorHttpClient.cs
WalletWasabi/Tor/Http/TorHttpClient.cs
@@ -208,13 +208,9 @@ namespace WalletWasabi.Tor.Http
request.Version = HttpProtocol.HTTP11.Version;
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
- if (TorSocks5Client is { } && !TorSocks5Client.IsConnected)
+ if (TorSocks5Client is null)
{
- TorSocks5Client?.Dispose();
- TorSocks5Client = null;
- }
-
- if (TorSocks5Client is null || !TorSocks5Client.IsConnected)
+ try
{
TorSocks5Client = new TorSocks5Client(TorSocks5EndPoint!);
await TorSocks5Client.ConnectAsync(cancel).ConfigureAwait(false);
@@ -226,6 +222,13 @@ namespace WalletWasabi.Tor.Http
await TorSocks5Client.UpgradeToSslAsync(host).ConfigureAwait(false);
}
}
+ catch
+ {
+ TorSocks5Client?.Dispose();
+ TorSocks5Client = null;
+ throw;
+ }
+ }
cancel.ThrowIfCancellationRequested();

MODIFY
WalletWasabi/Tor/Socks5/TorSocks5Client.cs
WalletWasabi/Tor/Socks5/TorSocks5Client.cs
@@ -46,8 +46,6 @@ namespace WalletWasabi.Tor.Socks5
private EndPoint RemoteEndPoint { get; set; }
- public bool IsConnected => TcpClient?.Connected is true;
-
internal AsyncLock AsyncLock { get; }
#endregion PropertiesAndMembers

Remove TorSocks5Client.IsConnected and make it more easy to follow the code.