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

Catch and ignore expected exceptions #1386

Merged
merged 1 commit into from
Jan 17, 2025
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
15 changes: 11 additions & 4 deletions backend/FwLite/FwLiteShared/Auth/OAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,18 @@ private readonly Channel<OAuthLoginRequest>

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await foreach (var loginRequest in _requestChannel.Reader.ReadAllAsync(stoppingToken))
try
{
await foreach (var loginRequest in _requestChannel.Reader.ReadAllAsync(stoppingToken))
{
//don't await, otherwise we'll block the channel reader and only 1 login will be processed at a time
//cancel the login after 5 minutes, otherwise it'll probably hang forever and abandoned requests will never be cleaned up
_ = Task.Run(() => StartLogin(loginRequest, stoppingToken.Merge(new CancellationTokenSource(TimeSpan.FromMinutes(5)).Token)), stoppingToken);
}
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
//don't await, otherwise we'll block the channel reader and only 1 login will be processed at a time
//cancel the login after 5 minutes, otherwise it'll probably hang forever and abandoned requests will never be cleaned up
_ = Task.Run(() => StartLogin(loginRequest, stoppingToken.Merge(new CancellationTokenSource(TimeSpan.FromMinutes(5)).Token)), stoppingToken);
// Expected during shutdown
}
}

Expand Down
15 changes: 11 additions & 4 deletions backend/FwLite/FwLiteShared/Sync/BackgroundSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,18 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await SyncProject(crdtProject, true, stoppingToken);
}

await foreach (var project in _syncResultsChannel.Reader.ReadAllAsync(stoppingToken))
try
{
await foreach (var project in _syncResultsChannel.Reader.ReadAllAsync(stoppingToken))
{
//todo, this might not be required, but I can't remember why I added it
await Task.Delay(100, stoppingToken);
await SyncProject(project, false, stoppingToken);
}
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
//todo, this might not be required, but I can't remember why I added it
await Task.Delay(100, stoppingToken);
await SyncProject(project, false, stoppingToken);
// Expected during shutdown
}
}

Expand Down
Loading