Fix fire-and-forget TriggerSyncAsync: log exceptions instead of silently discarding them#177
Open
davidortinau wants to merge 1 commit into
Open
Fix fire-and-forget TriggerSyncAsync: log exceptions instead of silently discarding them#177davidortinau wants to merge 1 commit into
davidortinau wants to merge 1 commit into
Conversation
…() helper Replace all 29 _syncService?.TriggerSyncAsync().ConfigureAwait(false) call sites across 9 repository files with a private TriggerSync() helper that runs the sync in Task.Run and catches/logs any exception via ILogger. Previously, unobserved task exceptions were silently discarded in .NET 5+. The .ConfigureAwait(false) on a non-awaited Task was also a no-op. Affected files: - LearningResourceRepository.cs (12 sites) - ScenarioRepository.cs (2 sites) - SkillProfileRepository.cs (2 sites) - StoryRepository.cs (2 sites) - StreamHistoryRepository.cs (2 sites) - UserActivityRepository.cs (2 sites) - UserProfileRepository.cs (3 sites) - VocabularyLearningContextRepository.cs (2 sites) - VocabularyProgressRepository.cs (2 sites) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every repository in
src/SentenceStudio.Shared/Data/called_syncService?.TriggerSyncAsync().ConfigureAwait(false)as fire-and-forget afterSaveChangesAsync(). In .NET 5+, unobserved task exceptions are silently discarded — no crash, no log..ConfigureAwait(false)on a non-awaitedTaskis also a no-op. IfTriggerSyncAsyncthrew (connection refused, auth failure, serialization error), the error was lost, the write appeared successful to the caller, and data never synced — with zero indication anything went wrong.Fix
Added a
private void TriggerSync()helper to each affected repository that runs the sync inTask.Runand catches/logs any exception viaILogger:Replaced all 29 silent call sites with
TriggerSync().Changes
LearningResourceRepository.csScenarioRepository.csSkillProfileRepository.csStoryRepository.csStreamHistoryRepository.csUserActivityRepository.csUserProfileRepository.csVocabularyLearningContextRepository.csVocabularyProgressRepository.csVerification
SentenceStudio.Sharedbuilds clean (0 errors)dotnet test tests/SentenceStudio.UnitTests)