Observe fire-and-forget startup tasks in WebHosting - #493
Merged
Conversation
_webApplication.StartAsync and StartupCache were started without being awaited or observed, so a startup failure of the web host or the cache initialization stayed silent. Both tasks are now tracked and any fault is logged through the application logger.
Read the AggregateException into a local before the null-conditional logger call so it is always observed, and log GetBaseException instead of the wrapping AggregateException. Drop the redundant Logging using directive already supplied by the Web SDK, document the new logger field, and move the helper methods into the existing Private methods region.
applicationData.Logger stays null unless OpenTelemetry logging is configured, which silently swallowed the newly observed startup faults in the default setup. The logger now falls back to the web application's own ILoggerFactory once the host is built. A faulting StartAsync also resets IsRunning so a host that failed to bind no longer reports itself as running.
|
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.



Summary
_webApplication.StartAsync(_cts.Token)andStartupCache(_cts.Token)inWebHosting.StartWebHostingwere started without being awaited or otherwise observed. The trailing.ConfigureAwait(false)onStartupCachehad no effect since the task was never awaited, so a startup failure of the web host or the cache initialization stayed completely silent.Both tasks are now tracked and observed through a new
ObserveStartupTaskhelper, which attaches a fault-only continuation that logs the exception via the application logger, without changing the fire-and-forget startup flow.Linked issues
Closes #195
Review notes
StartWebHostingremains synchronous by design (it is called from the non-asyncStartReceiving), so the fix keeps the startup calls fire-and-forget but ensures faults are logged rather than swallowed.