Repository navigation
Keep BackgroundService failures visible to the host behind the lifecycle decorator - #5819
Conversation
…cle decorator. The host only watches ExecuteTask and applies BackgroundServiceExceptionBehavior for services it sees as BackgroundService, so wrapping them in a plain IHostedService decorator hid their failures and made StopHost a no-op. Background services now get a decorator derived from BackgroundService that passes ExecuteTask through and delegates start/stop logging to the existing decorator. DB-2281 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change restoring host visibility into background-service failures while preserving lifecycle logging.
No open issues 🎉
What changed in this PR
Restores the generic host’s ability to observe background-service failures and apply BackgroundServiceExceptionBehavior while preserving lifecycle logging.
Changes:
- Adds a
BackgroundServicedecorator that exposes the wrapped service’s execution task and delegates lifecycle logging. - Updates hosted-service registration to select the appropriate decorator per instance.
- Adds tests for decorator selection, execution-task forwarding, and host shutdown on background-service failure.
| File | Description |
|---|---|
src/KurrentDB.Hosting/NodeWebApplication.cs |
Registers the instance-aware decorator factory. |
src/KurrentDB.Hosting/HostedServiceLifecycleDecorator.cs |
Adds decorator selection and preserves background-task visibility to the host. |
src/KurrentDB.Components.Tests/HostedServiceLifecycleDecoratorTests.cs |
Tests decorator behavior and the StopHost failure policy. |
Review effort: Balanced
This does not change how KurrentDB Release builds behave. Release builds of the server and the embedded node use
BackgroundServiceExceptionBehavior.Ignore, so a background service that fails never stopped the node and still won't. The only difference in Release is that the host's own error log for the failure is written again. Debug builds useStopHost, which had stopped working and works again.The lifecycle logging decorator from #5680 wraps every hosted service in a plain
IHostedService. The host only watchesExecuteTaskfor services it sees asBackgroundService, so behind the decorator it never noticed a background service fail after startup. Background services are now wrapped in a decorator derived fromBackgroundServicethat passesExecuteTaskthrough.IHostedLifecycleServicewould be hidden the same way, but nothing implements it today, so it is left out.Fixes DB-2281.
🤖 Generated with Claude Code