Skip to content

Conversation

@tjprescott
Copy link
Member

APIView has been crashing when I run it locally. This allegedly should fix the problem!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to prevent APIView from crashing when running locally by configuring the host to ignore exceptions from background services rather than terminating the application.

Key Changes:

  • Added HostOptions configuration to set BackgroundServiceExceptionBehavior.Ignore
  • Configured a 30-second shutdown timeout for background services

// Configure host options to prevent background service exceptions from crashing the app
services.Configure<HostOptions>(options =>
{
options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting BackgroundServiceExceptionBehavior.Ignore silently suppresses all exceptions from background services, which masks the root cause instead of fixing it. This approach has several operational concerns:

  1. Loss of observability: Exceptions that crash the app are visible and actionable. Ignored exceptions may go unnoticed until they cause data inconsistencies or silent failures.

  2. Existing exception handling: All background services in this codebase already have proper try-catch blocks with telemetry tracking (e.g., CopilotPollingBackgroundHostedService lines 50-57, ReviewBackgroundHostedService lines 75-83, QueuedHostedService lines 43-46). If the app is still crashing, it suggests exceptions are escaping these handlers, which indicates a bug that should be fixed rather than suppressed.

  3. Better alternatives:

    • Investigate which specific background service is throwing unhandled exceptions and fix the exception handling in that service
    • Use BackgroundServiceExceptionBehavior.StopHost (the default) to maintain fail-fast behavior while fixing the root cause
    • If you must use Ignore temporarily, add comprehensive logging to track when exceptions occur

Recommendation: Instead of ignoring exceptions globally, identify the specific background service causing crashes and add proper exception handling there. This maintains observability and follows the existing pattern used in the other services.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think that the best things would be actually identity from which line/call/process the exceptions is being thrown and see if we can fix it, in this case ignoring exception behavior will make debugging harder in the future, I will try to find the root cause

await ArchiveInactiveAPIReviews(stoppingToken, _autoArchiveInactiveGracePeriodMonths);
}
catch (Exception ex)
while (!stoppingToken.IsCancellationRequested)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we running this in loop? This is a onetime task to update reviews when a new version is deployed. right?

@tjprescott
Copy link
Member Author

This seems to be working for me now I'll close this unless the problem recurs, in which case I'll just open an issue.

@tjprescott tjprescott closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants