ConfigureAwait in Store related classes
MODIFY
WalletWasabi/Io/DigestableSafeMutexIoManager.cs
WalletWasabi/Io/DigestableSafeMutexIoManager.cs
@@ -61,15 +61,15 @@ namespace WalletWasabi.Io
ContinueBuildHash(byteArrayBuilder, line);
}
- var res = await WorkWithHashAsync(byteArrayBuilder, cancellationToken);
+ var res = await WorkWithHashAsync(byteArrayBuilder, cancellationToken).ConfigureAwait(false);
if (res.same)
{
return;
}
- await base.WriteAllLinesAsync(lines, cancellationToken);
+ await base.WriteAllLinesAsync(lines, cancellationToken).ConfigureAwait(false);
- await WriteOutHashAsync(res.hash);
+ await WriteOutHashAsync(res.hash).ConfigureAwait(false);
}
public new async Task AppendAllLinesAsync(IEnumerable<string> lines, CancellationToken cancellationToken = default)
@@ -104,7 +104,7 @@ namespace WalletWasabi.Io
{
if (line is null)
{
- line = await lineTask;
+ line = await lineTask.ConfigureAwait(false);
}
lineTask = sr.EndOfStream ? null : sr.ReadLineAsync();
@@ -115,7 +115,7 @@ namespace WalletWasabi.Io
continue;
}
- await wTask;
+ await wTask.ConfigureAwait(false);
wTask = sw.WriteLineAsync(line);
ContinueBuildHash(byteArrayBuilder, line);
@@ -124,31 +124,31 @@ namespace WalletWasabi.Io
line = null;
}
- await wTask;
+ await wTask.ConfigureAwait(false);
}
- await sw.FlushAsync();
+ await sw.FlushAsync().ConfigureAwait(false);
// 2. Then append.
foreach (var line in linesArray)
{
- await sw.WriteLineAsync(line);
+ await sw.WriteLineAsync(line).ConfigureAwait(false);
ContinueBuildHash(byteArrayBuilder, line);
cancellationToken.ThrowIfCancellationRequested();
}
- await sw.FlushAsync();
+ await sw.FlushAsync().ConfigureAwait(false);
}
- var res = await WorkWithHashAsync(byteArrayBuilder, cancellationToken);
+ var res = await WorkWithHashAsync(byteArrayBuilder, cancellationToken).ConfigureAwait(false);
if (res.same)
{
return;
}
SafeMoveNewToOriginal();
- await WriteOutHashAsync(res.hash);
+ await WriteOutHashAsync(res.hash).ConfigureAwait(false);
}
#endregion IoOperations
@@ -161,7 +161,7 @@ namespace WalletWasabi.Io
{
IoHelpers.EnsureContainingDirectoryExists(DigestFilePath);
- await File.WriteAllBytesAsync(DigestFilePath, hash);
+ await File.WriteAllBytesAsync(DigestFilePath, hash).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -179,7 +179,7 @@ namespace WalletWasabi.Io
hash = HashHelpers.GenerateSha256Hash(bytes);
if (File.Exists(DigestFilePath))
{
- var digest = await File.ReadAllBytesAsync(DigestFilePath, cancellationToken);
+ var digest = await File.ReadAllBytesAsync(DigestFilePath, cancellationToken).ConfigureAwait(false);
if (ByteHelpers.CompareFastUnsafe(hash, digest))
{
if (File.Exists(NewFilePath))

MODIFY
WalletWasabi/Io/IoManager.cs
WalletWasabi/Io/IoManager.cs
@@ -54,12 +54,12 @@ namespace WalletWasabi.Io
public async Task<string[]> ReadAllLinesAsync(CancellationToken cancellationToken = default)
{
- return await ReadAllLinesAsync(FilePath, cancellationToken);
+ return await ReadAllLinesAsync(FilePath, cancellationToken).ConfigureAwait(false);
}
protected static async Task<string[]> ReadAllLinesAsync(string filePath, CancellationToken cancellationToken)
{
- return await File.ReadAllLinesAsync(filePath, cancellationToken);
+ return await File.ReadAllLinesAsync(filePath, cancellationToken).ConfigureAwait(false);
}
/// <summary>
@@ -88,7 +88,7 @@ namespace WalletWasabi.Io
IoHelpers.EnsureContainingDirectoryExists(FilePath);
- await File.WriteAllLinesAsync(FilePath, lines, cancellationToken);
+ await File.WriteAllLinesAsync(FilePath, lines, cancellationToken).ConfigureAwait(false);
}
public async Task AppendAllLinesAsync(IEnumerable<string> lines, CancellationToken cancellationToken = default)
@@ -98,7 +98,7 @@ namespace WalletWasabi.Io
return;
}
- await File.AppendAllLinesAsync(FilePath, lines, cancellationToken);
+ await File.AppendAllLinesAsync(FilePath, lines, cancellationToken).ConfigureAwait(false);
}
#endregion IoOperations

MODIFY
WalletWasabi/Io/SafeMutexIoManager.cs
WalletWasabi/Io/SafeMutexIoManager.cs
@@ -133,7 +133,7 @@ namespace WalletWasabi.Io
IoHelpers.EnsureContainingDirectoryExists(NewFilePath);
- await File.WriteAllLinesAsync(NewFilePath, lines, cancellationToken);
+ await File.WriteAllLinesAsync(NewFilePath, lines, cancellationToken).ConfigureAwait(false);
SafeMoveNewToOriginal();
}
@@ -144,7 +144,7 @@ namespace WalletWasabi.Io
{
filePath = safestFilePath;
}
- return await ReadAllLinesAsync(filePath, cancellationToken);
+ return await ReadAllLinesAsync(filePath, cancellationToken).ConfigureAwait(false);
}
/// <summary>

MODIFY
WalletWasabi/Mempool/MempoolBehavior.cs
WalletWasabi/Mempool/MempoolBehavior.cs
@@ -38,7 +38,7 @@ namespace WalletWasabi.Mempool
{
if (message.Message.Payload is GetDataPayload getDataPayload)
{
- await ProcessGetDataAsync(node, getDataPayload);
+ await ProcessGetDataAsync(node, getDataPayload).ConfigureAwait(false);
return;
}
@@ -50,7 +50,7 @@ namespace WalletWasabi.Mempool
if (message.Message.Payload is InvPayload invPayload)
{
- await ProcessInvAsync(node, invPayload);
+ await ProcessInvAsync(node, invPayload).ConfigureAwait(false);
return;
}
}
@@ -91,7 +91,7 @@ namespace WalletWasabi.Mempool
}
else
{
- await node.SendMessageAsync(txPayload);
+ await node.SendMessageAsync(txPayload).ConfigureAwait(false);
entry.MakeBroadcasted();
Logger.LogInfo($"Successfully served transaction to node ({node.RemoteSocketEndpoint}): {entry.TransactionId}.");
}
@@ -144,7 +144,7 @@ namespace WalletWasabi.Mempool
if (getDataPayload.Inventory.Any() && node.IsConnected)
{
// ask for the whole transaction
- await node.SendMessageAsync(getDataPayload);
+ await node.SendMessageAsync(getDataPayload).ConfigureAwait(false);
}
}

MODIFY
WalletWasabi/Mempool/MempoolService.cs
WalletWasabi/Mempool/MempoolService.cs
@@ -117,7 +117,7 @@ namespace WalletWasabi.Mempool
using (var client = new WasabiClient(destAction, torSocks))
{
var compactness = 10;
- var allMempoolHashes = await client.GetMempoolHashesAsync(compactness);
+ var allMempoolHashes = await client.GetMempoolHashesAsync(compactness).ConfigureAwait(false);
lock (ProcessedLock)
{

MODIFY
WalletWasabi/Nito/AsyncEx/AsyncMutex.cs
WalletWasabi/Nito/AsyncEx/AsyncMutex.cs
@@ -231,7 +231,7 @@ namespace Nito.AsyncEx
while (!Done.WaitOne(1))
{
// Waiting for Done asynchronously.
- await Task.Delay(pollInterval, cancellationToken);
+ await Task.Delay(pollInterval, cancellationToken).ConfigureAwait(false);
}
lock (LatestHoldLockExceptionLock)
{
@@ -283,7 +283,7 @@ namespace Nito.AsyncEx
}
// Local lock for thread safety.
- await AsyncLock.LockAsync(cancellationToken);
+ await AsyncLock.LockAsync(cancellationToken).ConfigureAwait(false);
if (IsAlive)
{
@@ -301,7 +301,7 @@ namespace Nito.AsyncEx
try
{
// Create the mutex and acquire it.
- await SetCommandAsync(1, cancellationToken, pollInterval);
+ await SetCommandAsync(1, cancellationToken, pollInterval).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -412,7 +412,7 @@ namespace Nito.AsyncEx
}
Logger.LogDebug($"Waiting for: {string.Join(", ", AsyncMutexes.Where(am => am.Value.IsAlive).Select(m => m.Value.ShortName))}.");
}
- await Task.Delay(200);
+ await Task.Delay(200).ConfigureAwait(false);
if (DateTime.Now - start > TimeSpan.FromSeconds(60))
{
var mutexesAlive = AsyncMutexes.Where(am => am.Value.IsAlive).Select(m => m.Value.ShortName);

MODIFY
WalletWasabi/Stores/BitcoinStore.cs
WalletWasabi/Stores/BitcoinStore.cs
@@ -33,7 +33,7 @@ namespace WalletWasabi.Stores
IndexStore = new IndexStore();
var indexStoreFolderPath = Path.Combine(WorkFolderPath, Network.ToString(), "IndexStore");
HashChain = new HashChain();
- await IndexStore.InitializeAsync(indexStoreFolderPath, Network, HashChain);
+ await IndexStore.InitializeAsync(indexStoreFolderPath, Network, HashChain).ConfigureAwait(false);
}
}
}

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -55,13 +55,13 @@ namespace WalletWasabi.Stores
IndexLock = new AsyncLock();
- using (await IndexLock.LockAsync())
- using (await MatureIndexFileManager.Mutex.LockAsync())
- using (await ImmatureIndexFileManager.Mutex.LockAsync())
+ using (await IndexLock.LockAsync().ConfigureAwait(false))
+ using (await MatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
+ using (await ImmatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
{
IoHelpers.EnsureDirectoryExists(WorkFolderPath);
- await TryEnsureBackwardsCompatibilityAsync();
+ await TryEnsureBackwardsCompatibilityAsync().ConfigureAwait(false);
if (Network == Network.RegTest)
{
@@ -71,10 +71,10 @@ namespace WalletWasabi.Stores
if (!MatureIndexFileManager.Exists())
{
- await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToHeightlessLine() });
+ await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToHeightlessLine() }).ConfigureAwait(false);
}
- await InitializeFiltersAsync();
+ await InitializeFiltersAsync().ConfigureAwait(false);
}
}
}
@@ -96,7 +96,7 @@ namespace WalletWasabi.Stores
{
if (line is null)
{
- line = await lineTask;
+ line = await lineTask.ConfigureAwait(false);
}
lineTask = sr.EndOfStream ? null : sr.ReadLineAsync();
@@ -111,7 +111,7 @@ namespace WalletWasabi.Stores
if (ImmatureIndexFileManager.Exists())
{
- foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync()) // We can load ImmatureIndexFileManager to the memory, no problem.
+ foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync().ConfigureAwait(false)) // We can load ImmatureIndexFileManager to the memory, no problem.
{
ProcessLine(height, line, enqueue: true);
height++;
@@ -180,12 +180,12 @@ namespace WalletWasabi.Stores
if (File.Exists(oldIndexFilePath))
{
- string[] allLines = await File.ReadAllLinesAsync(oldIndexFilePath);
+ string[] allLines = await File.ReadAllLinesAsync(oldIndexFilePath).ConfigureAwait(false);
var matureLines = allLines.SkipLast(100);
var immatureLines = allLines.TakeLast(100);
- await MatureIndexFileManager.WriteAllLinesAsync(matureLines);
- await ImmatureIndexFileManager.WriteAllLinesAsync(immatureLines);
+ await MatureIndexFileManager.WriteAllLinesAsync(matureLines).ConfigureAwait(false);
+ await ImmatureIndexFileManager.WriteAllLinesAsync(immatureLines).ConfigureAwait(false);
File.Delete(oldIndexFilePath);
}
@@ -200,7 +200,7 @@ namespace WalletWasabi.Stores
{
foreach (var filter in filters)
{
- using (await IndexLock.LockAsync())
+ using (await IndexLock.LockAsync().ConfigureAwait(false))
{
ProcessFilter(filter, enqueue: true);
}
@@ -215,7 +215,7 @@ namespace WalletWasabi.Stores
{
FilterModel filter = null;
- using (await IndexLock.LockAsync())
+ using (await IndexLock.LockAsync().ConfigureAwait(false))
{
filter = ImmatureFilters.Last();
ImmatureFilters.RemoveLast();
@@ -236,7 +236,7 @@ namespace WalletWasabi.Stores
public async Task<IEnumerable<FilterModel>> RemoveAllImmmatureFiltersAsync(CancellationToken cancel, bool deleteAndCrashIfMature = false)
{
var removed = new List<FilterModel>();
- using (await IndexLock.LockAsync(cancel))
+ using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
{
if (ImmatureFilters.Any())
{
@@ -250,8 +250,8 @@ namespace WalletWasabi.Stores
{
Logger.LogCritical($"Deleting all filters and crashing the software...");
- using (await MatureIndexFileManager.Mutex.LockAsync(cancel))
- using (await ImmatureIndexFileManager.Mutex.LockAsync(cancel))
+ using (await MatureIndexFileManager.Mutex.LockAsync(cancel).ConfigureAwait(false))
+ using (await ImmatureIndexFileManager.Mutex.LockAsync(cancel).ConfigureAwait(false))
{
ImmatureIndexFileManager.DeleteMe();
MatureIndexFileManager.DeleteMe();
@@ -264,7 +264,7 @@ namespace WalletWasabi.Stores
while (ImmatureFilters.Any())
{
- removed.Add(await RemoveLastFilterAsync(cancel));
+ removed.Add(await RemoveLastFilterAsync(cancel).ConfigureAwait(false));
}
return removed;
@@ -287,7 +287,7 @@ namespace WalletWasabi.Stores
int incremented = Interlocked.Increment(ref _throttleId);
if (incremented < 21)
{
- await Task.Delay(throttle, cancel);
+ await Task.Delay(throttle, cancel).ConfigureAwait(false);
}
// If the _throttleId is still the incremented value, then I am the latest CommitToFileAsync request.
@@ -304,9 +304,9 @@ namespace WalletWasabi.Stores
Interlocked.Exchange(ref _throttleId, 0); // So to notify the currently throttled threads that they do not have to run.
}
- using (await MatureIndexFileManager.Mutex.LockAsync(cancel))
- using (await ImmatureIndexFileManager.Mutex.LockAsync(cancel))
- using (await IndexLock.LockAsync(cancel))
+ using (await MatureIndexFileManager.Mutex.LockAsync(cancel).ConfigureAwait(false))
+ using (await ImmatureIndexFileManager.Mutex.LockAsync(cancel).ConfigureAwait(false))
+ using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
{
// Do not feed the cancellationToken here I always want this to finish running for safety.
var currentImmatureLines = ImmatureFilters.Select(x => x.ToHeightlessLine()).ToArray(); // So we do not read on ImmatureFilters while removing them.
@@ -317,7 +317,7 @@ namespace WalletWasabi.Stores
{
ImmatureFilters.RemoveFirst();
}
- await Task.WhenAll(tasks);
+ await Task.WhenAll(tasks).ConfigureAwait(false);
}
}
catch (Exception ex) when (ex is OperationCanceledException || ex is TaskCanceledException || ex is TimeoutException)
@@ -332,8 +332,8 @@ namespace WalletWasabi.Stores
public async Task ForeachFiltersAsync(Func<FilterModel, Task> todo, Height fromHeight)
{
- using (await MatureIndexFileManager.Mutex.LockAsync())
- using (await IndexLock.LockAsync())
+ using (await MatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
+ using (await IndexLock.LockAsync().ConfigureAwait(false))
{
var firstImmatureHeight = ImmatureFilters.FirstOrDefault()?.BlockHeight;
if (!firstImmatureHeight.HasValue || firstImmatureHeight.Value > fromHeight)
@@ -356,7 +356,7 @@ namespace WalletWasabi.Stores
if (line is null)
{
- line = await lineTask;
+ line = await lineTask.ConfigureAwait(false);
}
lineTask = sr.EndOfStream ? null : sr.ReadLineAsync();
@@ -370,19 +370,19 @@ namespace WalletWasabi.Stores
var filter = FilterModel.FromHeightlessLine(line, height);
- await tTask;
+ await tTask.ConfigureAwait(false);
tTask = todo(filter);
height++;
line = null;
}
- await tTask;
+ await tTask.ConfigureAwait(false);
}
while (!sr.EndOfStream)
{
- var line = await sr.ReadLineAsync();
+ var line = await sr.ReadLineAsync().ConfigureAwait(false);
if (firstImmatureHeight == height)
{
@@ -397,7 +397,7 @@ namespace WalletWasabi.Stores
var filter = FilterModel.FromHeightlessLine(line, height);
- await todo(filter);
+ await todo(filter).ConfigureAwait(false);
height++;
}
}
@@ -405,7 +405,7 @@ namespace WalletWasabi.Stores
foreach (FilterModel filter in ImmatureFilters)
{
- await todo(filter);
+ await todo(filter).ConfigureAwait(false);
}
}
}

ConfigureAwait in Store related classes