Improve disposing of Tor items
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
@@ -49,13 +49,13 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
this.WhenAnyValue(x => x.CurrentTarget)
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(x =>
+ .Subscribe((Action<NavigationTarget>)(x =>
{
enableBack?.Dispose();
enableBack = Navigate()
- .WhenAnyValue(y => y.CanNavigateBack)
+ .WhenAnyValue<Navigation.INavigationStack<Navigation.RoutableViewModel>, bool>(y => y.CanNavigateBack)
.Subscribe(y => EnableBack = y);
- });
+ }));
this.WhenAnyValue(x => x.WalletName)
.ObserveOn(RxApp.MainThreadScheduler)

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -434,7 +434,7 @@ namespace WalletWasabi.Gui
return;
}
- Logger.LogDebug($"Step: Wait for initialization to complete.", nameof(Global));
+ Logger.LogDebug($"Waiting for initialization to complete.", nameof(Global));
try
{
@@ -446,12 +446,11 @@ namespace WalletWasabi.Gui
Logger.LogError($"Error during wait for initialization to be completed: {ex}");
}
- Logger.LogDebug($"Step: {nameof(WalletManager)}.", nameof(Global));
-
try
{
using var dequeueCts = new CancellationTokenSource(TimeSpan.FromMinutes(6));
await WalletManager.RemoveAndStopAllAsync(dequeueCts.Token).ConfigureAwait(false);
+ Logger.LogInfo($"{nameof(WalletManager)} is stopped.", nameof(Global));
}
catch (Exception ex)
{
@@ -461,8 +460,6 @@ namespace WalletWasabi.Gui
WalletManager.OnDequeue -= WalletManager_OnDequeue;
WalletManager.WalletRelevantTransactionProcessed -= WalletManager_WalletRelevantTransactionProcessed;
- Logger.LogDebug($"Step: {nameof(RpcServer)}.", nameof(Global));
-
if (RpcServer is { } rpcServer)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(21));
@@ -470,24 +467,18 @@ namespace WalletWasabi.Gui
Logger.LogInfo($"{nameof(RpcServer)} is stopped.", nameof(Global));
}
- Logger.LogDebug($"Step: {nameof(CoinJoinProcessor)}.", nameof(Global));
-
if (CoinJoinProcessor is { } coinJoinProcessor)
{
coinJoinProcessor.Dispose();
Logger.LogInfo($"{nameof(CoinJoinProcessor)} is disposed.");
}
- Logger.LogDebug($"Step: {nameof(LegalChecker)}.", nameof(Global));
-
if (LegalChecker is { } legalChecker)
{
legalChecker.Dispose();
Logger.LogInfo($"Disposed {nameof(LegalChecker)}.");
}
- Logger.LogDebug($"Step: {nameof(HostedServices)}.", nameof(Global));
-
if (HostedServices is { } backgroundServices)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(21));
@@ -496,53 +487,51 @@ namespace WalletWasabi.Gui
Logger.LogInfo("Stopped background services.");
}
- Logger.LogDebug($"Step: {nameof(Synchronizer)}.", nameof(Global));
-
if (Synchronizer is { } synchronizer)
{
await synchronizer.StopAsync().ConfigureAwait(false);
Logger.LogInfo($"{nameof(Synchronizer)} is stopped.");
}
- Logger.LogDebug($"Step: {nameof(BitcoinCoreNode)}.", nameof(Global));
+ if (HttpClientFactory is { } httpClientFactory)
+ {
+ httpClientFactory.Dispose();
+ Logger.LogInfo($"{nameof(HttpClientFactory)} is disposed.");
+ }
if (BitcoinCoreNode is { } bitcoinCoreNode)
{
await bitcoinCoreNode.DisposeAsync().ConfigureAwait(false);
+ Logger.LogInfo($"{nameof(BitcoinCoreNode)} is disposed.");
if (Config.StopLocalBitcoinCoreOnShutdown)
{
await bitcoinCoreNode.TryStopAsync().ConfigureAwait(false);
+ Logger.LogInfo($"{nameof(BitcoinCoreNode)} is stopped.");
}
}
- Logger.LogDebug($"Step: {nameof(TorManager)}.", nameof(Global));
-
if (TorManager is { } torManager)
{
await torManager.StopAsync(Config.TerminateTorOnExit).ConfigureAwait(false);
Logger.LogInfo($"{nameof(TorManager)} is stopped.");
}
- Logger.LogDebug($"Step: {nameof(Cache)}.", nameof(Global));
-
if (Cache is { } cache)
{
cache.Dispose();
+ Logger.LogInfo($"{nameof(Cache)} is disposed.");
}
- Logger.LogDebug($"Step: {nameof(BitcoinStore)}.", nameof(Global));
-
try
{
await BitcoinStore.DisposeAsync().ConfigureAwait(false);
+ Logger.LogInfo($"{nameof(BitcoinStore)} is disposed.");
}
catch (Exception ex)
{
Logger.LogError($"Error during the disposal of {nameof(BitcoinStore)}: {ex}");
}
-
- Logger.LogDebug($"Step: {nameof(SingleInstanceChecker)}.", nameof(Global));
}
catch (Exception ex)
{

MODIFY
WalletWasabi.Tests/IntegrationTests/BlockstreamInfoTests.cs
WalletWasabi.Tests/IntegrationTests/BlockstreamInfoTests.cs
@@ -31,9 +31,11 @@ namespace WalletWasabi.Tests.IntegrationTests
Assert.True(started, "Tor failed to start.");
}
- public Task DisposeAsync()
+ public async Task DisposeAsync()
{
- return Task.CompletedTask;
+ ClearnetHttpClientFactory.Dispose();
+ TorHttpClientFactory.Dispose();
+ await TorManager.StopAsync();
}
[Fact]

MODIFY
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
WalletWasabi.Tests/IntegrationTests/LiveServerTests.cs
@@ -41,9 +41,10 @@ namespace WalletWasabi.Tests.IntegrationTests
Assert.True(started, "Tor failed to start.");
}
- public Task DisposeAsync()
+ public async Task DisposeAsync()
{
- return Task.CompletedTask;
+ TorHttpPool.Dispose();
+ await TorManager.StopAsync();
}
#region Blockchain

MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -95,7 +95,7 @@ namespace WalletWasabi.Tests.IntegrationTests
using var nodes = new NodesGroup(network, connectionParameters, requirements: Constants.NodeRequirements);
KeyManager keyManager = KeyManager.CreateNew(out _, "password");
- HttpClientFactory httpClientFactory = new(Common.TorSocks5Endpoint, backendUriGetter: () => new Uri("http://localhost:12345"));
+ using HttpClientFactory httpClientFactory = new(Common.TorSocks5Endpoint, backendUriGetter: () => new Uri("http://localhost:12345"));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
var feeProvider = new HybridFeeProvider(synchronizer, null);

MODIFY
WalletWasabi.Tests/IntegrationTests/TorTests.cs
WalletWasabi.Tests/IntegrationTests/TorTests.cs
@@ -30,9 +30,10 @@ namespace WalletWasabi.Tests.IntegrationTests
Assert.True(started, "Tor failed to start.");
}
- public Task DisposeAsync()
+ public async Task DisposeAsync()
{
- return Task.CompletedTask;
+ TorHttpPool.Dispose();
+ await TorManager.StopAsync();
}
[Fact]

MODIFY
WalletWasabi.Tests/RegressionTests/BuildTests.cs
WalletWasabi.Tests/RegressionTests/BuildTests.cs
@@ -54,7 +54,7 @@ namespace WalletWasabi.Tests.RegressionTests
node.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 3. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);
@@ -210,7 +210,7 @@ namespace WalletWasabi.Tests.RegressionTests
node.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 3. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -1074,7 +1074,7 @@ namespace WalletWasabi.Tests.RegressionTests
{
(string password, IRPCClient rpc, Network network, Coordinator coordinator, _, BitcoinStore bitcoinStore, _) = await Common.InitializeTestEnvironmentAsync(RegTestFixture, 1);
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(3), 10000); // Start wasabi synchronizer service.
@@ -1180,7 +1180,7 @@ namespace WalletWasabi.Tests.RegressionTests
{
(string password, IRPCClient rpc, Network network, Coordinator coordinator, _, BitcoinStore bitcoinStore, _) = await Common.InitializeTestEnvironmentAsync(RegTestFixture, 1);
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(3), 10000); // Start wasabi synchronizer service.
@@ -1378,7 +1378,7 @@ namespace WalletWasabi.Tests.RegressionTests
node2.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 3. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -51,7 +51,7 @@ namespace WalletWasabi.Tests.RegressionTests
node.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 3. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);
@@ -532,7 +532,7 @@ namespace WalletWasabi.Tests.RegressionTests
node.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 3. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);
@@ -704,7 +704,7 @@ namespace WalletWasabi.Tests.RegressionTests
node.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 3. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);

MODIFY
WalletWasabi.Tests/RegressionTests/WalletTests.cs
WalletWasabi.Tests/RegressionTests/WalletTests.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Tests.RegressionTests
{
(_, IRPCClient rpc, _, _, _, BitcoinStore bitcoinStore, _) = await Common.InitializeTestEnvironmentAsync(RegTestFixture, 1);
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
try
@@ -139,7 +139,7 @@ namespace WalletWasabi.Tests.RegressionTests
var node = RegTestFixture.BackendRegTestNode;
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
@@ -244,7 +244,7 @@ namespace WalletWasabi.Tests.RegressionTests
node.Behaviors.Add(bitcoinStore.CreateUntrustedP2pBehavior());
// 2. Create wasabi synchronizer service.
- HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
+ using HttpClientFactory httpClientFactory = new(torEndPoint: null, backendUriGetter: () => new Uri(RegTestFixture.BackendEndPoint));
WasabiSynchronizer synchronizer = new(bitcoinStore, httpClientFactory);
FilterProcessor filterProcessor = new(synchronizer, bitcoinStore);
HybridFeeProvider feeProvider = new(synchronizer, null);

MODIFY
WalletWasabi/Services/UpdateChecker.cs
WalletWasabi/Services/UpdateChecker.cs
@@ -19,6 +19,7 @@ namespace WalletWasabi.Services
}
public event EventHandler<UpdateStatus>? UpdateStatusChanged;
+
private WasabiSynchronizer Synchronizer { get; }
public UpdateStatus UpdateStatus { get; private set; }
public WasabiClient WasabiClient { get; }

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -319,7 +319,6 @@ namespace WalletWasabi.Services
await Task.Delay(50).ConfigureAwait(false);
}
- HttpClientFactory.Dispose();
StopCts.Dispose();
EnableRequests(); // Enable requests (it's possible something is being blocked outside the class by AreRequestsBlocked.

MODIFY
WalletWasabi/WebClients/Wasabi/HttpClientFactory.cs
WalletWasabi/WebClients/Wasabi/HttpClientFactory.cs
@@ -10,7 +10,7 @@ namespace WalletWasabi.WebClients.Wasabi
/// <summary>
/// Factory class to get proper <see cref="IHttpClient"/> client which is set up based on user settings.
/// </summary>
- public class HttpClientFactory
+ public class HttpClientFactory : IDisposable
{
/// <summary>
/// To detect redundant calls.

Improve disposing of Tor items