dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.31k stars 9.97k forks source link

Running multiple IServer's #27213

Open Tratcher opened 3 years ago

Tratcher commented 3 years ago

The current web host builder is designed to only work with only one IServer. It even relies on the DI behavior of using the last one registered so IIS can dynamically replace kestrel. We've had a few requests for applications that want to run Kestrel + HttpSys for example, to take advantage of their different capabilities. They don't want to start two processes or two hosts, they want to share a DI container, host infrastructure, and app pipeline.

From a pipeline perspective this should be fine, requests are processed one HttpContext at a time so there shouldn't be any cross contamination issues between the servers. The issues are mostly around setup.

Challenges: A) Activation: how do you configure the host to create and start multiple servers? Could IIS be supported as one of those servers, or just Kestrel and HttpSys? Could you have multiple instances of one kind of server like Kestrel? B) Configuration: how do you configure the bindings for those servers? They'd both try to consume the shared ASPNETCORE_URLS config. Luckily each server has its own programmatic config API. C) IServerAddresses: This advertises the bindings for the server to the application. The servers would have to avoid stomping on eachother updating this. D) What middleware make assumptions about working with a single server?

ghost commented 3 years ago

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.

JKamsker commented 2 years ago

@Tratcher did you find a way to solve this issue?

mconnew commented 1 year ago

This scenario is important for CoreWCF as we need to use Kestrel alongside other IServer implementations. The primary one having one endpoint listening on HTTP while hosted in IIS, and one or more endpoints using Kestrel to listen on NetTcp, UnixDomainSocket, and/or NetNamedPipe. Currently we construct Kestrel using ActivatorUtilities.CreateInstance when the primary IServer isn't already Kestrel. As we're adding UnixDomainSocket support, we'll also do this when the primary IServer is Kestrel, but using TCP sockets.

slaneyrw commented 1 year ago

Another use-case is to attach to Azure Relay (Microsoft.Azure.Relay.AspNetCore) and route incoming requests from the hybrid connection along side Kestrel/HTTPSys