diff --git a/src/Databento.Client/DataSources/Caching/DiskRecordCache.cs b/src/Databento.Client/DataSources/Caching/DiskRecordCache.cs index b9aee5a..b5a34a8 100644 --- a/src/Databento.Client/DataSources/Caching/DiskRecordCache.cs +++ b/src/Databento.Client/DataSources/Caching/DiskRecordCache.cs @@ -122,7 +122,7 @@ public async IAsyncEnumerable ReadAsync([EnumeratorCancellation] Cancell using var reader = new DbnFileReader(_cacheFilePath); long index = 0; - await foreach (var record in reader.ReadRecordsAsync(cancellationToken)) + await foreach (var record in reader.ReadRecordsAsync(cancellationToken).ConfigureAwait(false)) { index++; yield return record; @@ -140,7 +140,7 @@ public async IAsyncEnumerable ReadFromIndexAsync(long startIndex, [Enume using var reader = new DbnFileReader(_cacheFilePath); long index = 0; - await foreach (var record in reader.ReadRecordsAsync(cancellationToken)) + await foreach (var record in reader.ReadRecordsAsync(cancellationToken).ConfigureAwait(false)) { if (index >= startIndex) { diff --git a/src/Databento.Client/DataSources/Caching/MemoryRecordCache.cs b/src/Databento.Client/DataSources/Caching/MemoryRecordCache.cs index f025605..6962f22 100644 --- a/src/Databento.Client/DataSources/Caching/MemoryRecordCache.cs +++ b/src/Databento.Client/DataSources/Caching/MemoryRecordCache.cs @@ -79,7 +79,7 @@ public async IAsyncEnumerable ReadAsync([EnumeratorCancellation] Cancell yield return record; } - await Task.CompletedTask; // Keep async signature + await Task.CompletedTask.ConfigureAwait(false); // Keep async signature } /// @@ -100,7 +100,7 @@ public async IAsyncEnumerable ReadFromIndexAsync(long startIndex, [Enume yield return snapshot[i]; } - await Task.CompletedTask; // Keep async signature + await Task.CompletedTask.ConfigureAwait(false); // Keep async signature } /// diff --git a/src/Databento.Client/DataSources/FileDataSource.cs b/src/Databento.Client/DataSources/FileDataSource.cs index 402d785..1d14648 100644 --- a/src/Databento.Client/DataSources/FileDataSource.cs +++ b/src/Databento.Client/DataSources/FileDataSource.cs @@ -133,7 +133,7 @@ public async IAsyncEnumerable StreamAsync([EnumeratorCancellation] Cance long index = 0; long? previousNanos = null; - await foreach (var record in _reader.ReadRecordsAsync(linkedCts.Token)) + await foreach (var record in _reader.ReadRecordsAsync(linkedCts.Token).ConfigureAwait(false)) { // Check for pause/stop if (!await Playback.WaitIfPausedAsync(linkedCts.Token).ConfigureAwait(false)) @@ -235,6 +235,6 @@ public async ValueTask DisposeAsync() _reader?.Dispose(); Interlocked.Exchange(ref _disposeState, 2); - await Task.CompletedTask; + await Task.CompletedTask.ConfigureAwait(false); } } diff --git a/src/Databento.Client/DataSources/HistoricalDataSource.cs b/src/Databento.Client/DataSources/HistoricalDataSource.cs index a0b7c25..97f27a4 100644 --- a/src/Databento.Client/DataSources/HistoricalDataSource.cs +++ b/src/Databento.Client/DataSources/HistoricalDataSource.cs @@ -167,7 +167,7 @@ public async IAsyncEnumerable StreamAsync([EnumeratorCancellation] Cance subscription.Symbols, _startTime, _endTime, - linkedCts.Token)) + linkedCts.Token).ConfigureAwait(false)) { // Check for pause/stop if (!await Playback.WaitIfPausedAsync(linkedCts.Token).ConfigureAwait(false)) diff --git a/src/Databento.Client/DataSources/LiveDataSource.cs b/src/Databento.Client/DataSources/LiveDataSource.cs index 0f7cf47..f22eb63 100644 --- a/src/Databento.Client/DataSources/LiveDataSource.cs +++ b/src/Databento.Client/DataSources/LiveDataSource.cs @@ -229,7 +229,7 @@ public async IAsyncEnumerable StreamAsync([EnumeratorCancellation] Cance if (_recordChannel == null) throw new InvalidOperationException("Not connected. Call ConnectAsync() first."); - await foreach (var record in _recordChannel.Reader.ReadAllAsync(cancellationToken)) + await foreach (var record in _recordChannel.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false)) { yield return record; } diff --git a/src/Databento.Client/Historical/HistoricalClient.cs b/src/Databento.Client/Historical/HistoricalClient.cs index d6a0c14..d3eaed8 100644 --- a/src/Databento.Client/Historical/HistoricalClient.cs +++ b/src/Databento.Client/Historical/HistoricalClient.cs @@ -268,7 +268,7 @@ public async IAsyncEnumerable GetRangeAsync( }, cancellationToken); // Stream results - await foreach (var record in channel.Reader.ReadAllAsync(cancellationToken)) + await foreach (var record in channel.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false)) { yield return record; } @@ -427,7 +427,7 @@ public async IAsyncEnumerable GetRangeAsync( }, cancellationToken); // Stream results - await foreach (var record in channel.Reader.ReadAllAsync(cancellationToken)) + await foreach (var record in channel.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false)) { yield return record; } diff --git a/src/Databento.Client/Live/BacktestingClient.cs b/src/Databento.Client/Live/BacktestingClient.cs index 71a0dd1..0ac4058 100644 --- a/src/Databento.Client/Live/BacktestingClient.cs +++ b/src/Databento.Client/Live/BacktestingClient.cs @@ -188,7 +188,7 @@ public async IAsyncEnumerable StreamAsync([EnumeratorCancellation] Cance Interlocked.Exchange(ref _connectionState, (int)ConnectionState.Streaming); - await foreach (var record in _dataSource.StreamAsync(cancellationToken)) + await foreach (var record in _dataSource.StreamAsync(cancellationToken).ConfigureAwait(false)) { // Fire event DataReceived?.Invoke(this, new DataReceivedEventArgs(record)); diff --git a/src/Databento.Client/Live/LiveClient.cs b/src/Databento.Client/Live/LiveClient.cs index 7ea7d50..61e256f 100644 --- a/src/Databento.Client/Live/LiveClient.cs +++ b/src/Databento.Client/Live/LiveClient.cs @@ -147,7 +147,7 @@ internal LiveClient( _healthMonitor = new ConnectionHealthMonitor( _resilienceOptions, _logger, - async ct => await PerformReconnectAsync(ct)); + PerformReconnectAsync); } // MEDIUM FIX: Use Interlocked for consistency Interlocked.Exchange(ref _connectionState, (int)ConnectionState.Disconnected); @@ -584,7 +584,7 @@ public async Task ResubscribeAsync(CancellationToken cancellationToken = default throw DbentoException.CreateFromErrorCode($"Resubscription failed: {error}", result); } - await Task.CompletedTask; + await Task.CompletedTask.ConfigureAwait(false); } /// @@ -616,7 +616,7 @@ private async Task PerformReconnectAsync(CancellationToken cancellationToken) public async IAsyncEnumerable StreamAsync( [EnumeratorCancellation] CancellationToken cancellationToken = default) { - await foreach (var record in _recordChannel.Reader.ReadAllAsync(cancellationToken)) + await foreach (var record in _recordChannel.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false)) { yield return record; } diff --git a/src/Databento.Client/Reference/AdjustmentFactorsApi.cs b/src/Databento.Client/Reference/AdjustmentFactorsApi.cs index 19a4173..ebcc828 100644 --- a/src/Databento.Client/Reference/AdjustmentFactorsApi.cs +++ b/src/Databento.Client/Reference/AdjustmentFactorsApi.cs @@ -83,12 +83,12 @@ public async Task> GetRangeAsync( var url = $"{_baseUrl}/v0/adjustment_factors.get_range"; _logger.LogDebug("POST {Url}", url); - // MEDIUM FIX: Execute with retry policy for transient failures - var content = new FormUrlEncodedContent(queryParams); + // MEDIUM FIX: Execute with retry policy for transient failures var response = await _retryPolicy.ExecuteAsync(async () => { - return await _httpClient.PostAsync(url, content, cancellationToken); - }); + var content = new FormUrlEncodedContent(queryParams); + return await _httpClient.PostAsync(url, content, cancellationToken).ConfigureAwait(false); + }).ConfigureAwait(false); await ReferenceApiHelpers.EnsureSuccessStatusCode(response).ConfigureAwait(false); // Parse JSONL response (Databento Reference API returns JSON Lines format) diff --git a/src/Databento.Client/Reference/CorporateActionsApi.cs b/src/Databento.Client/Reference/CorporateActionsApi.cs index 946cebc..7df7f33 100644 --- a/src/Databento.Client/Reference/CorporateActionsApi.cs +++ b/src/Databento.Client/Reference/CorporateActionsApi.cs @@ -111,12 +111,12 @@ public async Task> GetRangeAsync( var url = $"{_baseUrl}/v0/corporate_actions.get_range"; _logger.LogDebug("POST {Url}", url); - // MEDIUM FIX: Execute with retry policy for transient failures - var content = new FormUrlEncodedContent(queryParams); + // MEDIUM FIX: Execute with retry policy for transient failures var response = await _retryPolicy.ExecuteAsync(async () => { - return await _httpClient.PostAsync(url, content, cancellationToken); - }); + var content = new FormUrlEncodedContent(queryParams); + return await _httpClient.PostAsync(url, content, cancellationToken).ConfigureAwait(false); + }).ConfigureAwait(false); await ReferenceApiHelpers.EnsureSuccessStatusCode(response).ConfigureAwait(false); // Parse JSONL response (Databento Reference API returns JSON Lines format) diff --git a/src/Databento.Client/Reference/ReferenceClient.cs b/src/Databento.Client/Reference/ReferenceClient.cs index 8f5b7a4..4c58a21 100644 --- a/src/Databento.Client/Reference/ReferenceClient.cs +++ b/src/Databento.Client/Reference/ReferenceClient.cs @@ -133,6 +133,6 @@ public async ValueTask DisposeAsync() _httpClient?.Dispose(); _disposed = true; - await Task.CompletedTask; + await Task.CompletedTask.ConfigureAwait(false); } } diff --git a/src/Databento.Client/Reference/SecurityMasterApi.cs b/src/Databento.Client/Reference/SecurityMasterApi.cs index 1c00aad..75ed402 100644 --- a/src/Databento.Client/Reference/SecurityMasterApi.cs +++ b/src/Databento.Client/Reference/SecurityMasterApi.cs @@ -84,12 +84,12 @@ public async Task> GetLastAsync( try { - // MEDIUM FIX: Execute with retry policy for transient failures - var content = new FormUrlEncodedContent(queryParams); + // MEDIUM FIX: Execute with retry policy for transient failures var response = await _retryPolicy.ExecuteAsync(async () => { - return await _httpClient.PostAsync(url, content, cancellationToken); - }); + var content = new FormUrlEncodedContent(queryParams); + return await _httpClient.PostAsync(url, content, cancellationToken).ConfigureAwait(false); + }).ConfigureAwait(false); await ReferenceApiHelpers.EnsureSuccessStatusCode(response).ConfigureAwait(false); // Parse JSONL response (Databento Reference API returns JSON Lines format) @@ -174,12 +174,12 @@ public async Task> GetRangeAsync( var url = $"{_baseUrl}/v0/security_master.get_range"; _logger.LogDebug("POST {Url}", url); - // MEDIUM FIX: Execute with retry policy for transient failures - var content = new FormUrlEncodedContent(queryParams); + // MEDIUM FIX: Execute with retry policy for transient failures var response = await _retryPolicy.ExecuteAsync(async () => { - return await _httpClient.PostAsync(url, content, cancellationToken); - }); + var content = new FormUrlEncodedContent(queryParams); + return await _httpClient.PostAsync(url, content, cancellationToken).ConfigureAwait(false); + }).ConfigureAwait(false); await ReferenceApiHelpers.EnsureSuccessStatusCode(response).ConfigureAwait(false); // Parse JSONL response (Databento Reference API returns JSON Lines format) diff --git a/src/Databento.Client/Resilience/ConnectionHealthMonitor.cs b/src/Databento.Client/Resilience/ConnectionHealthMonitor.cs index a506dcc..da6ac14 100644 --- a/src/Databento.Client/Resilience/ConnectionHealthMonitor.cs +++ b/src/Databento.Client/Resilience/ConnectionHealthMonitor.cs @@ -120,7 +120,7 @@ private async Task MonitorLoopAsync() { try { - await Task.Delay(checkInterval, _cts.Token); + await Task.Delay(checkInterval, _cts.Token).ConfigureAwait(false); var timeSinceActivity = DateTime.UtcNow - _lastActivityTime; @@ -136,7 +136,7 @@ private async Task MonitorLoopAsync() if (_options.AutoReconnect) { await TryReconnectAsync( - new TimeoutException($"No activity for {timeSinceActivity.TotalSeconds:F1} seconds")); + new TimeoutException($"No activity for {timeSinceActivity.TotalSeconds:F1} seconds")).ConfigureAwait(false); } } } @@ -189,11 +189,11 @@ private async Task TryReconnectAsync(Exception triggerException) "Reconnection attempt {Attempt}/{Max} in {Delay:F1}s", attempt + 1, _options.RetryPolicy.MaxRetries, delay.TotalSeconds); - await Task.Delay(delay, _cts.Token); + await Task.Delay(delay, _cts.Token).ConfigureAwait(false); try { - await _reconnectAction(_cts.Token); + await _reconnectAction(_cts.Token).ConfigureAwait(false); // Success! ReconnectionCount++;