Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure await false everywhere #247

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Enyim.Caching/DistributedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ byte[] IDistributedCache.Get(string key)

async Task<byte[]> IDistributedCache.GetAsync(string key, CancellationToken token = default)
{
var value = await GetValueAsync<byte[]>(key);
var value = await GetValueAsync<byte[]>(key).ConfigureAwait(false);

if (value != null)
{
await RefreshAsync(key);
await RefreshAsync(key).ConfigureAwait(false);
}

return value;
Expand Down Expand Up @@ -58,17 +58,17 @@ void IDistributedCache.Set(string key, byte[] value, DistributedCacheEntryOption
{
if (!HasSlidingExpiration(options))
{
await PerformStoreAsync(StoreMode.Set, key, value, 0);
await PerformStoreAsync(StoreMode.Set, key, value, 0).ConfigureAwait(false);
return;
}

var expiration = GetExpiration(options);
await PerformStoreAsync(StoreMode.Set, key, value, expiration);
await PerformStoreAsync(StoreMode.Set, key, value, expiration).ConfigureAwait(false);

if (options.SlidingExpiration.HasValue)
{
var sldExp = options.SlidingExpiration.Value;
await AddAsync(GetSlidingExpirationKey(key), sldExp.ToString(), sldExp);
await AddAsync(GetSlidingExpirationKey(key), sldExp.ToString(), sldExp).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -108,15 +108,15 @@ public void Refresh(string key)
public async Task RefreshAsync(string key, CancellationToken token = default)
{
var sldExpKey = GetSlidingExpirationKey(key);
var sldExpStr = await GetValueAsync<string>(sldExpKey);
var sldExpStr = await GetValueAsync<string>(sldExpKey).ConfigureAwait(false);
if (!string.IsNullOrEmpty(sldExpStr)
&& TimeSpan.TryParse(sldExpStr, out var sldExp))
{
var value = (await GetAsync(key)).Value;
var value = (await GetAsync(key).ConfigureAwait(false)).Value;
if (value != null)
{
await ReplaceAsync(key, value, sldExp);
await ReplaceAsync(sldExpKey, sldExpStr, sldExp);
await ReplaceAsync(key, value, sldExp).ConfigureAwait(false);
await ReplaceAsync(sldExpKey, sldExpStr, sldExp).ConfigureAwait(false);
}
}
}
Expand All @@ -129,8 +129,8 @@ void IDistributedCache.Remove(string key)

async Task IDistributedCache.RemoveAsync(string key, CancellationToken token = default)
{
await RemoveAsync(key);
await RemoveAsync(GetSlidingExpirationKey(key));
await RemoveAsync(key).ConfigureAwait(false);
await RemoveAsync(GetSlidingExpirationKey(key)).ConfigureAwait(false);
}

private uint GetExpiration(DistributedCacheEntryOptions options)
Expand Down
44 changes: 22 additions & 22 deletions src/Enyim.Caching/Memcached/MemcachedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public async Task<IPooledSocketResult> AcquireAsync()
var result = new PooledSocketResult();
if (!_isInitialized)
{
if (!await poolInitSemaphore.WaitAsync(_initPoolTimeout))
if (!await poolInitSemaphore.WaitAsync(_initPoolTimeout).ConfigureAwait(false))
{
return result.Fail("Timeout to poolInitSemaphore.Wait", _logger) as PooledSocketResult;
}
Expand All @@ -224,7 +224,7 @@ public async Task<IPooledSocketResult> AcquireAsync()
if (!_isInitialized)
{
var startTime = DateTime.Now;
await _internalPoolImpl.InitPoolAsync();
await _internalPoolImpl.InitPoolAsync().ConfigureAwait(false);
_isInitialized = true;

if (_logger.IsEnabled(LogLevel.Information))
Expand All @@ -242,7 +242,7 @@ public async Task<IPooledSocketResult> AcquireAsync()

try
{
return await _internalPoolImpl.AcquireAsync();
return await _internalPoolImpl.AcquireAsync().ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down Expand Up @@ -397,7 +397,7 @@ internal async Task InitPoolAsync()
{
try
{
_freeItems.Push(await CreateSocketAsync());
_freeItems.Push(await CreateSocketAsync().ConfigureAwait(false));
}
catch (Exception ex)
{
Expand All @@ -423,7 +423,7 @@ internal async Task InitPoolAsync()

private async Task<PooledSocket> CreateSocketAsync()
{
var ps = await _ownerNode.CreateSocketAsync();
var ps = await _ownerNode.CreateSocketAsync().ConfigureAwait(false);
ps.CleanupCallback = ReleaseSocket;

return ps;
Expand Down Expand Up @@ -586,7 +586,7 @@ public async Task<IPooledSocketResult> AcquireAsync()

PooledSocket socket = null;

if (!await _semaphore.WaitAsync(_queueTimeout))
if (!await _semaphore.WaitAsync(_queueTimeout).ConfigureAwait(false))
{
message = "Pool is full, timeouting. " + _endPoint;
if (_isDebugEnabled) _logger.LogDebug(message);
Expand Down Expand Up @@ -616,9 +616,9 @@ public async Task<IPooledSocketResult> AcquireAsync()
{
var resetTask = socket.ResetAsync();

if (await Task.WhenAny(resetTask, Task.Delay(_receiveTimeout)) == resetTask)
if (await Task.WhenAny(resetTask, Task.Delay(_receiveTimeout)).ConfigureAwait(false) == resetTask)
{
await resetTask;
await resetTask.ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -662,7 +662,7 @@ public async Task<IPooledSocketResult> AcquireAsync()
{
// okay, create the new item
var startTime = DateTime.Now;
socket = await CreateSocketAsync();
socket = await CreateSocketAsync().ConfigureAwait(false);

if (_logger.IsEnabled(LogLevel.Information))
{
Expand Down Expand Up @@ -927,13 +927,13 @@ protected internal virtual async Task<PooledSocket> CreateSocketAsync()
{
try
{
return await CreateSocketInternalAsync();
return await CreateSocketInternalAsync().ConfigureAwait(false);
}
catch
{
try
{
return await CreateSocketInternalAsync();
return await CreateSocketInternalAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -951,7 +951,7 @@ private async Task<PooledSocket> CreateSocketInternalAsync()
#else
_useSslStream, _useIPv6);
#endif
await ps.ConnectAsync();
await ps.ConnectAsync().ConfigureAwait(false);
return ps;
}

Expand Down Expand Up @@ -1018,7 +1018,7 @@ protected virtual async Task<IPooledSocketResult> ExecuteOperationAsync(IOperati
_logger.LogDebug($"ExecuteOperationAsync({op})");
}

var result = await AcquireAsync();
var result = await AcquireAsync().ConfigureAwait(false);
if (result.Success && result.HasValue)
{
try
Expand All @@ -1034,13 +1034,13 @@ protected virtual async Task<IPooledSocketResult> ExecuteOperationAsync(IOperati
}

var writeSocketTask = pooledSocket.WriteAsync(b);
if (await Task.WhenAny(writeSocketTask, Task.Delay(_config.ConnectionTimeout)) != writeSocketTask)
if (await Task.WhenAny(writeSocketTask, Task.Delay(_config.ConnectionTimeout)).ConfigureAwait(false) != writeSocketTask)
{
result.Fail("Timeout to pooledSocket.WriteAsync");
return result;
}

await writeSocketTask;
await writeSocketTask.ConfigureAwait(false);

//if Get, call BinaryResponse
if (_logger.IsEnabled(LogLevel.Debug))
Expand All @@ -1049,13 +1049,13 @@ protected virtual async Task<IPooledSocketResult> ExecuteOperationAsync(IOperati
}

var readResponseTask = op.ReadResponseAsync(pooledSocket);
if (await Task.WhenAny(readResponseTask, Task.Delay(_config.ConnectionTimeout)) != readResponseTask)
if (await Task.WhenAny(readResponseTask, Task.Delay(_config.ConnectionTimeout)).ConfigureAwait(false) != readResponseTask)
{
result.Fail($"Timeout to ReadResponseAsync(pooledSocket) for {op}");
return result;
}

var readResult = await readResponseTask;
var readResult = await readResponseTask.ConfigureAwait(false);
if (readResult.Success)
{
result.Pass();
Expand Down Expand Up @@ -1103,22 +1103,22 @@ protected virtual async Task<IPooledSocketResult> ExecuteOperationAsync(IOperati

protected virtual async Task<bool> ExecuteOperationAsync(IOperation op, Action<bool> next)
{
var socket = (await AcquireAsync()).Value;
var socket = (await AcquireAsync().ConfigureAwait(false)).Value;
if (socket == null) return false;

//key(string) to buffer(btye[])
var b = op.GetBuffer();

try
{
await socket.WriteAsync(b);
await socket.WriteAsync(b).ConfigureAwait(false);

var rrs = await op.ReadResponseAsync(socket, readSuccess =>
{
((IDisposable)socket).Dispose();

next(readSuccess);
});
}).ConfigureAwait(false);

return rrs;
}
Expand Down Expand Up @@ -1164,12 +1164,12 @@ IOperationResult IMemcachedNode.Execute(IOperation op)

async Task<IOperationResult> IMemcachedNode.ExecuteAsync(IOperation op)
{
return await ExecuteOperationAsync(op);
return await ExecuteOperationAsync(op).ConfigureAwait(false);
}

async Task<bool> IMemcachedNode.ExecuteAsync(IOperation op, Action<bool> next)
{
return await ExecuteOperationAsync(op, next);
return await ExecuteOperationAsync(op, next).ConfigureAwait(false);
}

event Action<IMemcachedNode> IMemcachedNode.Failed
Expand Down
22 changes: 10 additions & 12 deletions src/Enyim.Caching/Memcached/PooledSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public async Task<bool> ConnectAsync()
{
var connTask = _socket.ConnectAsync(_endpoint);

if (await Task.WhenAny(connTask, Task.Delay(_connectionTimeout)) == connTask)
if (await Task.WhenAny(connTask, Task.Delay(_connectionTimeout)).ConfigureAwait(false) == connTask)
{
await connTask;
await connTask.ConfigureAwait(false);
}
else
{
Expand All @@ -174,7 +174,7 @@ public async Task<bool> ConnectAsync()
{
var ep = GetIPEndPoint(_endpoint);
if (_isSocketDisposed) return false;
await _socket.ConnectAsync(ep.Address, ep.Port);
await _socket.ConnectAsync(ep.Address, ep.Port).ConfigureAwait(false);
}

if (_socket != null)
Expand All @@ -200,7 +200,7 @@ await _sslStream.AuthenticateAsClientAsync(
#else
((DnsEndPoint)_endpoint).Host
#endif
);
).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -253,8 +253,6 @@ public void Reset()

public async Task ResetAsync()
{
// await _inputStream.FlushAsync();

int available = _socket.Available;

if (available > 0)
Expand All @@ -268,7 +266,7 @@ public async Task ResetAsync()

byte[] data = new byte[available];

await ReadAsync(data, 0, available);
await ReadAsync(data, 0, available).ConfigureAwait(false);
}

if (_logger.IsEnabled(LogLevel.Debug))
Expand Down Expand Up @@ -428,8 +426,8 @@ public async Task ReadAsync(byte[] buffer, int offset, int count)
try
{
int currentRead = (_useSslStream
? await _sslStream.ReadAsync(buffer, offset, shouldRead)
: await _inputStream.ReadAsync(buffer, offset, shouldRead));
? await _sslStream.ReadAsync(buffer, offset, shouldRead).ConfigureAwait(false)
: await _inputStream.ReadAsync(buffer, offset, shouldRead).ConfigureAwait(false));
if (currentRead == count)
break;
if (currentRead < 1)
Expand Down Expand Up @@ -578,14 +576,14 @@ public async Task WriteAsync(IList<ArraySegment<byte>> buffers)
{
foreach (var buf in buffers)
{
await _sslStream.WriteAsync(buf.Array, 0, buf.Count);
await _sslStream.WriteAsync(buf.Array, 0, buf.Count).ConfigureAwait(false);
}

await _sslStream.FlushAsync();
await _sslStream.FlushAsync().ConfigureAwait(false);
}
else
{
var bytesTransferred = await _socket.SendAsync(buffers, SocketFlags.None);
var bytesTransferred = await _socket.SendAsync(buffers, SocketFlags.None).ConfigureAwait(false);
if (bytesTransferred <= 0)
{
_isAlive = false;
Expand Down
10 changes: 5 additions & 5 deletions src/Enyim.Caching/Memcached/Protocol/Binary/BinaryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ protected internal override PooledSocket CreateSocket()

protected internal override async Task<PooledSocket> CreateSocketAsync()
{
var retval = await base.CreateSocketAsync();
var retval = await base.CreateSocketAsync().ConfigureAwait(false);

if (_authenticationProvider != null && !(await AuthAsync(retval)))
if (_authenticationProvider != null && !await AuthAsync(retval).ConfigureAwait(false))
{
_logger.LogError("Authentication failed: " + EndPoint);

Expand Down Expand Up @@ -105,15 +105,15 @@ private async Task<bool> AuthAsync(PooledSocket socket)
{
SaslStep currentStep = new SaslStart(_authenticationProvider);

await socket.WriteAsync(currentStep.GetBuffer());
await socket.WriteAsync(currentStep.GetBuffer()).ConfigureAwait(false);

while (!(await currentStep.ReadResponseAsync(socket)).Success)
while (!(await currentStep.ReadResponseAsync(socket).ConfigureAwait(false)).Success)
{
// challenge-response authentication
if (currentStep.StatusCode == 0x21)
{
currentStep = new SaslContinue(_authenticationProvider, currentStep.Data);
await socket.WriteAsync(currentStep.GetBuffer());
await socket.WriteAsync(currentStep.GetBuffer()).ConfigureAwait(false);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Enyim.Caching/Memcached/Protocol/Binary/BinaryResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task<bool> ReadAsync(PooledSocket socket)
if (!socket.IsAlive) return false;

var header = new byte[HeaderLength];
await socket.ReadAsync(header, 0, header.Length);
await socket.ReadAsync(header, 0, header.Length).ConfigureAwait(false);

int dataLength, extraLength;

Expand All @@ -89,7 +89,7 @@ public async Task<bool> ReadAsync(PooledSocket socket)
if (dataLength > 0)
{
var data = new byte[dataLength];
await socket.ReadAsync(data, 0, dataLength);
await socket.ReadAsync(data, 0, dataLength).ConfigureAwait(false);

Extra = new ArraySegment<byte>(data, 0, extraLength);
Data = new ArraySegment<byte>(data, extraLength, data.Length - extraLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
protected internal override async ValueTask<IOperationResult> ReadResponseAsync(PooledSocket socket)
{
var response = new BinaryResponse();
var retval = await response.ReadAsync(socket);
var retval = await response.ReadAsync(socket).ConfigureAwait(false);

Cas = response.CAS;
StatusCode = response.StatusCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
protected internal override async ValueTask<IOperationResult> ReadResponseAsync(PooledSocket socket)
{
var response = new BinaryResponse();
var retval = await response.ReadAsync(socket);
var retval = await response.ReadAsync(socket).ConfigureAwait(false);

StatusCode = StatusCode;
var result = new BinaryOperationResult()
Expand Down
Loading
Loading