Skip to content

Obsolete KestrelServer (just the public type, not all of Kestrel!) #47686

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

Open
JamesNK opened this issue Apr 13, 2023 · 11 comments
Open

Obsolete KestrelServer (just the public type, not all of Kestrel!) #47686

JamesNK opened this issue Apr 13, 2023 · 11 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions blocked The work on this issue is blocked due to some dependency
Milestone

Comments

@JamesNK
Copy link
Member

JamesNK commented Apr 13, 2023

Kestrel is designed for DI. But there is a public way to create it directly: KestrelServer.cs

This is forcing various hacks on us:

  • The real implementation of IServer is internal - KestrelServerImpl - and is wrapped by KestrelServer.
  • Adding new DI types to KestrelServer forces us to consider how KestrelServer passes them to KestrelServerImpl. See metrics PR and Andrew's TLS PR.
  • Falling behind on functionality. For example, KestrelServer doesn't support HTTP/3 (no ctor overload was added for specifying multiplexed transports).

Prior art in this area:

I think we should obsolete KestrelServer and require creating it with a builder.

@JamesNK JamesNK changed the title Obsolete KestrelServer? Obsolete KestrelServer (just the public type, not all of Kestrel!) Apr 13, 2023
@adityamandaleeka
Copy link
Member

Click-bait title! 🤣

@JamesNK
Copy link
Member Author

JamesNK commented Apr 17, 2023

I tried to make it less click bait.

@JamesNK
Copy link
Member Author

JamesNK commented Apr 17, 2023

We should help fix this code: natemcmaster/LettuceEncrypt@2ca07d2/src/LettuceEncrypt/Internal/AcmeCertificateLoader.cs#L43

Probably. But assuming KestrelServerImpl is the new IServer type then it should continue to work. It starts with KestrelServer.

@amcasey
Copy link
Member

amcasey commented May 1, 2023

We should help fix this code: natemcmaster/LettuceEncrypt@2ca07d2/src/LettuceEncrypt/Internal/AcmeCertificateLoader.cs#L43

Probably. But assuming KestrelServerImpl is the new IServer type then it should continue to work. It starts with KestrelServer.

Given that the project is in maintenance mode, I'd be inclined to let it keep working "by accident" (though calling StartsWith seems like a very intentional choice?).

@amcasey
Copy link
Member

amcasey commented May 1, 2023

So what's the process here? Create an API issue suggesting we add the attribute?

@amcasey amcasey self-assigned this May 1, 2023
@Tratcher
Copy link
Member

Tratcher commented May 1, 2023

We already treat it as obsolete, adding the attribute seems fine.

I don't think an API issue is warranted. I'll just put the labels on this one.

@Tratcher Tratcher added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label May 1, 2023
@ghost
Copy link

ghost commented May 1, 2023

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@halter73
Copy link
Member

halter73 commented May 2, 2023

Probably. But assuming KestrelServerImpl is the new IServer type then it should continue to work. It starts with KestrelServer.

I think the workaround for anyone using nameof(KestrelServer) is to just hard code "KestrelSever" to avoid obsoletion warnings. Nothing guarantees that the real Kestrel IServer really starts with nameof(KestrelServer), so using a string literal should be no more fragile.

I also agree we should keep it working. There's no reason to rename the real Kestrel IServer to something that doesn't start with KestrelServer at this point.

So what's the process here? Create an API issue suggesting we add the attribute?

I think it's still worth filling out the API proposal template. I'll do it though.

Background and Motivation

See primary issue.

Proposed API

namespace Microsoft.AspNetCore.Server.Kestrel.Core;

+ [Obsolete]
public class KestrelServer : IServer
{
}

Usage Examples

Old usages of new KestrelServer(...) would be encouraged to use a host and resolve the IServer instead?

// Before (now obsolete)
var kestrelOptions = new KestrelServerOptions();
//  ...
var server = new KestrelServer(
    Options.Create(kestrelOptions),
    new SocketTransportFactory(Options.Create(new SocketTransportOptions()), new LoggerFactory()),
    new LoggerFactory());

// After
var server = new HostBuilder().ConfigureWebHost(webBuilder =>
{
    webBuilder.UseKestrel(kestrelOptions =>
    {
        // ...
    }
}).Build().Services.GetRequiredService<IServer>();

// Usage of IServer vs KestrelServer should be the same.

Alternative Designs

  • Leave KestrelServer public.
  • Add an AddKestrelServer extension method to IServiceCollection so you can use Kestrel as an IServer with just a DI container without needing to configure a Host.

Risks

  • There are some usages of new KestrelServer(... which you can find with this query: https://grep.app/search?q=new%20KestrelServer%28. That code would need to be updated to use a host or at least a DI container which some people might be morally opposed to.

@halter73 halter73 added blocked The work on this issue is blocked due to some dependency api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels May 11, 2023
@halter73
Copy link
Member

halter73 commented May 11, 2023

API Review Notes:

  • @mconnew says he wants this API for CoreWCF.
    • It already uses it here.
    • Can we just use separate IServiceCollections/providers?
      • They want a shared DI container for multiple server instances.
      • Could Kestrel's IServer ServiceDescriptor be copied as transient? 😝
        • This was a joke, but it needs to work when IIS is the main IServer for the container.
  • What if hosting just started every IServer instead? This could be super breaking for existing apps expecting the last one to win. See Running multiple IServer's #27213
  • Instead should KestrelServer be the real IServer instead of KestrelServerImpl again?
    • It's annoying to make public API changes every time we consume a new service in Kestrel.
  • If we did obsolete this, we would not delete it until @mconnew's scenario is addressed.
  • The main issue this address is that this type does not support HTTP/3, and that seems worthwhile even though this isn't commonly used to begin with.

Blocked on #27213.

@halter73 halter73 added this to the Backlog milestone May 11, 2023
@ghost
Copy link

ghost commented May 11, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions blocked The work on this issue is blocked due to some dependency
Projects
None yet
Development

No branches or pull requests

6 participants