Fix enless loop when exiting during filter processing
MODIFY
WalletWasabi.Gui/Tabs/WalletManager/HardwareWallets/ConnectHardwareWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/HardwareWallets/ConnectHardwareWalletViewModel.cs
@@ -390,16 +390,16 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.HardwareWallets
// Successfully initialized.
Owner.OnClose();
}
+ catch (OperationCanceledException ex)
+ {
+ Logger.LogTrace(ex);
+ }
catch (Exception ex)
{
- // Initialization failed.
NotificationHelpers.Error(ex.ToUserFriendlyString());
- if (!(ex is OperationCanceledException))
- {
Logger.LogError(ex);
}
}
- }
finally
{
IsBusy = false;

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
@@ -205,7 +205,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
Owner.OnClose();
}
}
- catch (TaskCanceledException ex) when (ex is TaskCanceledException || ex is OperationCanceledException)
+ catch (OperationCanceledException ex)
{
Logger.LogTrace(ex);
}

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -398,10 +398,10 @@ namespace WalletWasabi.Stores
}
}
- public async Task ForeachFiltersAsync(Func<FilterModel, Task> todo, Height fromHeight)
+ public async Task ForeachFiltersAsync(Func<FilterModel, Task> todo, Height fromHeight, CancellationToken cancel)
{
- using (await MatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
- using (await IndexLock.LockAsync().ConfigureAwait(false))
+ using (await MatureIndexFileManager.Mutex.LockAsync(cancel).ConfigureAwait(false))
+ using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
{
var firstImmatureHeight = ImmatureFilters.FirstOrDefault()?.Header?.Height;
if (!firstImmatureHeight.HasValue || firstImmatureHeight.Value > fromHeight)

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -522,7 +522,7 @@ namespace WalletWasabi.Wallets
await ProcessFilterModelAsync(filterModel, cancel);
}
},
- new Height(bestKeyManagerHeight.Value + 1));
+ new Height(bestKeyManagerHeight.Value + 1), cancel);
}
private async Task LoadDummyMempoolAsync()
@@ -651,14 +651,14 @@ namespace WalletWasabi.Wallets
// If no connection, wait, then continue.
while (Nodes.ConnectedNodes.Count == 0)
{
- await Task.Delay(100);
+ await Task.Delay(100, cancel);
}
// Select a random node we are connected to.
Node node = Nodes.ConnectedNodes.RandomElement();
if (node is null || !node.IsConnected)
{
- await Task.Delay(100);
+ await Task.Delay(100, cancel);
continue;
}
@@ -667,7 +667,8 @@ namespace WalletWasabi.Wallets
{
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(RuntimeParams.Instance.NetworkNodeTimeout))) // 1/2 ADSL 512 kbit/s 00:00:32
{
- block = await node.DownloadBlockAsync(hash, cts.Token);
+ using var lts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, cancel);
+ block = await node.DownloadBlockAsync(hash, lts.Token);
}
// Validate block
@@ -712,7 +713,7 @@ namespace WalletWasabi.Wallets
}
// Save the block
- using (await BlockFolderLock.LockAsync())
+ using (await BlockFolderLock.LockAsync(cancel))
{
var path = Path.Combine(BlockFolderPath, hash.ToString());
await File.WriteAllBytesAsync(path, block.ToBytes());

Fix enless loop when exiting during filter processing