Skip to content

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

Open
@Roganik

Description

@Roganik

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-iisIncludes: IIS, ANCM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions