Skip to content

Move HostAbortedException to Abstractions#70205

Merged
eerhardt merged 2 commits intodotnet:mainfrom
eerhardt:MoveHostAbortedExceptionToAbstractions
Jun 6, 2022
Merged

Move HostAbortedException to Abstractions#70205
eerhardt merged 2 commits intodotnet:mainfrom
eerhardt:MoveHostAbortedExceptionToAbstractions

Conversation

@eerhardt
Copy link
Member

@eerhardt eerhardt commented Jun 3, 2022

HostAbortedException was added directly to Microsoft.Extensions.Hosting, which depends on a lot of other libraries. This causes problems when using the HostFactoryResolver.Sources package because now consumers of HostFactoryResolver need to reference the whole Hosting package and all of its dependencies.

Fix this by moving the new exception to the Hosting.Abstractions library, which has a minimal set of dependencies.

I couldn't add a dependency from HostFactoryResolver.Sources to Hosting.Abstractions. The packing infrastructure is getting in my way of doing that (cc @ViktorHofer). @dougbu - to consume HostFactoryResolver.Sources, you will need to manually add a reference to Microsoft.Extensions.Hosting.Abstractions.

 HostAbortedException was added directly to Microsoft.Extensions.Hosting, which depends on a lot of other libraries. This causes problems when using the HostFactoryResolver.Sources package because now consumers of HostFactoryResolver need to reference the whole Hosting package and all of its dependencies.

 Fix this by moving the new exception to the Hosting.Abstractions library, which has a minimal set of dependencies.
@ghost
Copy link

ghost commented Jun 3, 2022

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned eerhardt Jun 3, 2022
@ghost
Copy link

ghost commented Jun 3, 2022

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

Issue Details

HostAbortedException was added directly to Microsoft.Extensions.Hosting, which depends on a lot of other libraries. This causes problems when using the HostFactoryResolver.Sources package because now consumers of HostFactoryResolver need to reference the whole Hosting package and all of its dependencies.

Fix this by moving the new exception to the Hosting.Abstractions library, which has a minimal set of dependencies.

I couldn't add a dependency from HostFactoryResolver.Sources to Hosting.Abstractions. The packing infrastructure is getting in my way of doing that (cc @ViktorHofer). @dougbu - to consume HostFactoryResolver.Sources, you will need to manually add a reference to Microsoft.Extensions.Hosting.Abstractions.

Author: eerhardt
Assignees: -
Labels:

area-Extensions-Hosting

Milestone: -

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Were there any tests that should be moved as well?

@eerhardt
Copy link
Member Author

eerhardt commented Jun 3, 2022

Were there any tests that should be moved as well?

There are tests in Microsoft.Extensions.Hosting, but we don't have test projects for any of the MS.Ext.XXX.Abstractions libraries.

@eerhardt
Copy link
Member Author

eerhardt commented Jun 3, 2022

runtime (Build Browser wasm Linux Release LibraryTests) Failing after 68m

It's fitting that my PR fails for the flaky test that I'm trying to fix in another PR

@dougbu
Copy link
Contributor

dougbu commented Jun 3, 2022

Please see dotnet/aspnetcore#41999 (comment). Short story is this won't work in aspnetcore and violates the purpose of the .Sources package.

@dougbu - to consume HostFactoryResolver.Sources, you will need to manually add a reference to Microsoft.Extensions.Hosting.Abstractions.

Can't do this w/o limiting an "inside man" library to 7.0.0-preview6 or later web sites.

As I said in dotnet/aspnetcore#41999,

May be better to either stick w/ only throwing InvalidOperationException but making StopTheHostException public.

@deeprobin
Copy link
Contributor

Imo we should introduce a test project for Abstractions-specific things.

But everything else looks good to me.

Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

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

Please find another way to make the Exception public

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 3, 2022
@deeprobin
Copy link
Contributor

Please find another way to make the Exception public

why?

@dougbu
Copy link
Contributor

dougbu commented Jun 3, 2022

Please find another way to make the Exception public

why?

Because any 7.0.x dependencies makes the .Sources package useless in https://github.com/dotnet/aspnetcore/blob/main/src/Tools/GetDocumentInsider/src/GetDocument.Insider.csproj and massively limits the applicable scope of the Microsoft.Extensions.ApiDescription.Client package. Please see #70205 (comment)

…ions.Hosting assemblies.

Load the HostAbortedException using Reflection instead. If it can't be found, throw a private exception with the same name.
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 6, 2022
@eerhardt eerhardt requested review from davidfowl and dougbu June 6, 2022 16:30
@eerhardt
Copy link
Member Author

eerhardt commented Jun 6, 2022

I have changed HostFactoryResolver to follow the suggestion in dotnet/aspnetcore#41999 (comment). This removes the direct dependency on Microsoft.Extensions.Hosting assemblies, which should address @dougbu's feedback above.

Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

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

Liking it 😺

_hostTcs.TrySetException(new InvalidOperationException("The entry point exited without ever building an IHost."));
}
catch (TargetInvocationException tie) when (tie.InnerException is HostAbortedException)
catch (TargetInvocationException tie) when (tie.InnerException?.GetType().Name == "HostAbortedException")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Should this instead check the Exception's full name❔

Copy link
Member Author

@eerhardt eerhardt Jun 6, 2022

Choose a reason for hiding this comment

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

The private exception purposefully has a different full name (since it is nested). So we would need to check 2 different "full names".

Even full names wouldn't prevent some other code running in a Host "Build()" sequence naming their exception Microsoft.Extensions.Hosting.HostAbortedException. So it isn't a guaranteed solution either.

If, for some reason, someone else names their exception HostAbortedException, and it isn't the one we threw below, the caller will get null back from HostFactoryResolver.ResolveServiceProviderFactory, and it will handle it just like any other case where the IServiceProvider can't be found (usually displaying a message to the user saying something went wrong).

@eerhardt
Copy link
Member Author

eerhardt commented Jun 6, 2022

Merging to unblock aspnetcore taking a new runtime version. I can handle any follow up feedback in a separate PR.

@eerhardt eerhardt merged commit 542bcf4 into dotnet:main Jun 6, 2022
@eerhardt eerhardt deleted the MoveHostAbortedExceptionToAbstractions branch June 6, 2022 21:38
@ghost ghost locked as resolved and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants