-
Notifications
You must be signed in to change notification settings - Fork 227
[APIView] Fix background service crashing APIView #13469
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
Conversation
There was a problem hiding this 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
HostOptionsconfiguration to setBackgroundServiceExceptionBehavior.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; |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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:
-
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.
-
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.
-
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
|
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. |
APIView has been crashing when I run it locally. This allegedly should fix the problem!