Skip to content

HttpSysRequestDelegationFeature - DelegationRule.Dipose() doesn't clean up delegation flag with http.sys #27126

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

Closed
NGloreous opened this issue Oct 22, 2020 · 1 comment · Fixed by #28342
Assignees
Labels
affected-very-few This issue impacts very few customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. severity-minor This label is used by an internal tool
Milestone

Comments

@NGloreous
Copy link
Contributor

NGloreous commented Oct 22, 2020

Describe the bug

When a new DelegationRule is created, SetDelegationProperty gets called to add a HttpServerDelegationProperty property flag to the RequestQueue owned/created by the process (i.e. not the RequestQueue the delegator is trying to delegate to). When a DelegationRule is disposed, this property flag is not unset. This keeps the delegator process linked to destination queue and prevents a new DelegationRule rule for the same from being created later on.

Ideally as a consumer of this feature I want to be able to dynamically add/remove rules in production via config without the need to restart the process and this bug blocks this ability.

Here is a example fix that I've validated which unsets the property when disposing the delegation rule: master...NGloreous:user/nglore/delegation/unsetdelegation

To Reproduce

namespace Sample
{
    public class Startup
    {
        private DelegationRule _delegationRule;

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime, IWebHostEnvironment env)
        {
            var delegator = app.ServerFeatures.Get<IServerDelegationFeature>();

            app.Run(context =>
            {
                using (delegationRule = delegator.CreateDelegationRule("DefaultAppPool", "http://*:80/"))
                {
                    var transferFeature = context.Features.Get<IHttpSysRequestTransferFeature>();
                    transferFeature.TransferRequest(delegationRule);
                    return Task.CompletedTask;
                }
            });
        }
    }
}

Exceptions (if any)

With the above code, the first request received works fine (assuming you have the fix for #26982) but on subsequent request the below exception is throw from the call to CreateDelegationRule.

Microsoft.AspNetCore.Server.HttpSys.HttpSysException (183): Cannot create a file when that file already exists.
         at Microsoft.AspNetCore.Server.HttpSys.UrlGroup.SetProperty(HTTP_SERVER_PROPERTY property, IntPtr info, UInt32 infosize, Boolean throwOnError)
         at Microsoft.AspNetCore.Server.HttpSys.UrlGroup.SetDelegationProperty(RequestQueue destination)
         at Microsoft.AspNetCore.Server.HttpSys.ServerDelegationPropertyFeature.CreateDelegationRule(String queueName, String uri)

Also if you run "netsh http show servicestate" after making the first request you will see that the delegator process is still attached to the queue.

    Request queue name: DefaultAppPool
        Security descriptor: O:BAG:SYD:AI(A;;FR;;;S-1-5-82-3006700770-424185619-1745488364-794895919-4004696415)(A;;FA;;;SY)(A;;0x12019f;;;BA)
        Version: 2.0
        State: Active
        Request queue 503 verbosity level: Limited
        Max requests: 1000
        Number of active processes attached: 2
        Controller process:
            ID: 6436, image: C:\Windows\System32\svchost.exe
        Processes:
            ID: 4836, image: C:\Windows\System32\inetsrv\w3wp.exe
            ID: 2800, image: C:\Users\Administrator\Desktop\delegator\delegator.exe
        Registered URLs:
            HTTP://*:80/
@ghost
Copy link

ghost commented Oct 23, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@jkotalik jkotalik added affected-very-few This issue impacts very few customers bug This issue describes a behavior which is not expected - a bug. severity-minor This label is used by an internal tool labels Nov 13, 2020 — with ASP.NET Core Issue Ranking
@ghost ghost closed this as completed in #28342 Dec 11, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 10, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-very-few This issue impacts very few customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. severity-minor This label is used by an internal tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants