Skip to content

HttpContext.RequestAborted is not canceled when app is hosted under IIS with hostingModel = OutOfProcess #54936

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
1 task done
Roganik opened this issue Apr 4, 2024 · 1 comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-iis Includes: IIS, ANCM

Comments

@Roganik
Copy link

Roganik commented Apr 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Cancellation token HttpContext.RequestAborted is not triggered when App is hosted in IIS with such configuration:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="." inheritInChildApplications="false">
        <system.webServer>
            <handlers>
                <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
            </handlers>
            <aspNetCore processPath="dotnet" arguments=".\SlowWeatherInIIS.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
        </system.webServer>
    </location>
</configuration>

Method example:

    private readonly ILogger<WeatherForecastController> _logger;
   
    [HttpGet(Name = "GetWeatherForecast")]
    public async Task<IEnumerable<WeatherForecast>> Get()
    {
        _logger.Log(LogLevel.Information, "Got New Weather Request");
        this.HttpContext.RequestAborted.Register(() =>
        {
            _logger.Log(LogLevel.Information,$"Request aborted");
        });

        await Task.Delay(TimeSpan.FromSeconds(10), this.HttpContext.RequestAborted);
        // return logic here
    }

Issue that seems related:

Expected Behavior

Cancellation token HttpContext.RequestAborted should trigger when a user cancels http request to IIS when app is hosted with AspNetCoreModuleV2 with hostingModel = OutOfProcess

Steps To Reproduce

Case1 - cancelation doesn't work in IIS

  1. Clone repo: https://github.com/Roganik/SlowWeatherInIIS
  2. Publish the app with dotnet publish -c Release
  3. Host this app in IIS (you might need to install .NET Core Hosting Bundle).
    3.1 In my case I created the new website pointing to the publish output folder C:\Projects\SlowWeatherInIIS\bin\Release\net8.0\publish
    3.2 And I bind it to the 8081 port
  4. Open the url in browser
    4.1 Open http://localhost:8081/WeatherForecast and wait 10 seconds for output
    4.2 Open http://localhost:8081/WeatherForecast again, but cancel request before it finishes (just close browser tab)
  5. Check logs in logs folder C:\Projects\SlowWeatherInIIS\bin\Release\net8.0\publish\logs

Actual: Has two "Got New Weather Request" logs.
Expected: Has two "Got New Weather Request" logs and has one "Request aborted" log.

The "Request aborted" log is missing.

Case2 - cancelation works as expected when hosted by kerstel only

  1. Clone repo: https://github.com/Roganik/SlowWeatherInIIS
  2. Publish the app with dotnet publish -c Release
  3. Start the app
    3.1 Navigate to publish folder (in my case C:\Projects\SlowWeatherInIIS\bin\Release\net8.0\publish )
    3.2 Start web service in cmd: dotnet .\SlowWeatherInIIS.dll
    3.3 Read the base url of app from console. (in my case http://localhost:5000 )
  4. Open the url in browser.
    4.1 Open http://localhost:5000/WeatherForecast and wait 10 seconds for output
    4.2 Open http://localhost:5000/WeatherForecast again but cancel request before it finishes (just close browser tab)
  5. Check logs in cmd

Actual: Has two "Got New Weather Request" logs and has one "Request aborted" log
Expected: Actual behavior matches expected.

Exceptions (if any)

No response

.NET Version

8.0.103

Anything else?

Reproduced this behavior locally with:

  • Microsoft .Net 8.0.3 - Windows Server Hosting
  • IIS Version 10.0.22621.1
  • Windows: 23H2 (OS Build 22631.3235)
@ghost ghost added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 4, 2024
@amcasey amcasey added the feature-iis Includes: IIS, ANCM label Apr 5, 2024
@leopowershield
Copy link

Any improvement on this issue? I'm also facing the same issue, is there a solution for this limitation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-iis Includes: IIS, ANCM
Projects
None yet
Development

No branches or pull requests

3 participants