TorControlClient: Switch from IDisposable to IAsyncDisposable.
MODIFY
WalletWasabi.Tests/UnitTests/Tor/Control/TorControlFactoryTests.cs
WalletWasabi.Tests/UnitTests/Tor/Control/TorControlFactoryTests.cs
@@ -37,7 +37,7 @@ namespace WalletWasabi.Tests.UnitTests.Tor.Control
Pipe toServer = new();
Pipe toClient = new();
- using TorControlClient testClient = new(pipeReader: toClient.Reader, pipeWriter: toServer.Writer);
+ await using TorControlClient testClient = new(pipeReader: toClient.Reader, pipeWriter: toServer.Writer);
Logger.LogTrace("Client: Start authentication task.");
Task<TorControlClient> authenticationTask = clientFactory.AuthSafeCookieOrThrowAsync(testClient, cookieString, timeoutCts.Token);
@@ -45,7 +45,7 @@ namespace WalletWasabi.Tests.UnitTests.Tor.Control
Logger.LogTrace("Server: Read 'AUTHCHALLENGE SAFECOOKIE' command from the client.");
string authChallengeCommand = await toServer.Reader.ReadLineAsync(timeoutCts.Token);
- Logger.LogTrace($"Server: Received authchallenge line: '{authChallengeCommand}'.");
+ Logger.LogTrace($"Server: Received AUTHCHALLENGE line: '{authChallengeCommand}'.");
Assert.Equal("AUTHCHALLENGE SAFECOOKIE 6F14C18D5B00BF54E16E4728A4BFC81B1FF469F0B012CD71D9724BFBE14DB5E6", authChallengeCommand);
Logger.LogTrace("Server: Respond to client's AUTHCHALLENGE request.");

MODIFY
WalletWasabi/Tor/Control/TorControlClient.cs
WalletWasabi/Tor/Control/TorControlClient.cs
@@ -12,10 +12,8 @@ namespace WalletWasabi.Tor.Control
/// <summary>
/// Client already authenticated to Tor Control.
/// </summary>
- public class TorControlClient : IDisposable
+ public class TorControlClient : IAsyncDisposable
{
- private volatile bool _disposedValue = false; // To detect redundant calls
-
public TorControlClient(TcpClient tcpClient)
{
TcpClient = tcpClient;
@@ -99,22 +97,11 @@ namespace WalletWasabi.Tor.Control
return reply;
}
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
+ public ValueTask DisposeAsync()
{
TcpClient?.Dispose();
- }
- _disposedValue = true;
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
+ return ValueTask.CompletedTask;
}
}
}

MODIFY
WalletWasabi/Tor/Control/TorControlClientFactory.cs
WalletWasabi/Tor/Control/TorControlClientFactory.cs
@@ -55,7 +55,10 @@ namespace WalletWasabi.Tor.Control
}
finally
{
- clientToDispose?.Dispose();
+ if (clientToDispose is not null)
+ {
+ await clientToDispose.DisposeAsync().ConfigureAwait(false);
+ }
}
}

MODIFY
WalletWasabi/Tor/TorProcessManager.cs
WalletWasabi/Tor/TorProcessManager.cs
@@ -186,7 +186,7 @@ namespace WalletWasabi.Tor
}
// Leads to Tor termination because we sent TAKEOWNERSHIP command.
- torControlClient.Dispose();
+ await torControlClient.DisposeAsync().ConfigureAwait(false);
}
// Dispose Tor process resources (does not stop/kill Tor process).

TorControlClient: Switch from IDisposable to IAsyncDisposable.