Skip to content

IISExpress logs multiple “Request ended” per request when using HttpResponseMessage with StreamContent #184

Closed
@binki

Description

@binki

When I have an action that returns HttpResponseMessage with Content set to a StreamContent and run it in OWIN on IIS Express, I get multiple “Request ended” messages per request. There are more extra lines if the Stream I pass is longer. I assume that I should only ever see one such message in IIS Express. Since this happens when using this particular stack, I assume the issue is with how Web API or OWIN SystemWeb interacts with IIS Express and not an issue with IIS Express itself.

To get this behavior, I have an action handler which returns an HttpResponseMessage with a StreamContent:

public HttpResponseMessage Get() {
  var response = Request.CreateResponse();
  response.Content = new StreamContent(GetStreamFromSomewhere());
  return response;
}

I have my app configured with an OWIN runner:

[assembly: OwinStartup(typeof(WebApplication1.Startup1))]

namespace WebApplication1
{
    public class Startup1
    {
        public void Configuration(IAppBuilder app)
        {
            var httpConfiguration = new HttpConfiguration();
            httpConfiguration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new
            {
                id = RouteParameter.Optional,
            });

            app.UseWebApi(httpConfiguration);
        }
    }
}

Configured to be served by IISExpress in applicationhost.config:

<site name="WebApplication1" id="2">
    <application path="/">
        <virtualDirectory path="/" physicalPath="%USERPROFILE%\source\repos\WebApplication1\WebApplication1" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation=":8080:localhost" />
    </bindings>
</site>

And then run IISExpress:

C:\Users\binki>"\Program Files\IIS Express\iisexpress.exe" /Site:WebApplication1
Starting IIS Express ...
Successfully registered URL "http://localhost:8080/" for site "WebApplication1" application "/"
Registration completed for site "WebApplication1"
IIS Express is running.
Enter 'Q' to stop IIS Express

And make a single request with curl:

$ curl -sS -o/dev/null http://localhost:8080/api/values

Then IISExpress logs multiple “Request ended” lines (at least two per response, more if the stream is longer):

Request started: "GET" http://localhost:8080/api/values
Request ended: http://localhost:8080/api/values with HTTP status 200.0
Request ended: http://localhost:8080/api/values with HTTP status 200.0
Request ended: http://localhost:8080/api/values with HTTP status 200.0
Request ended: http://localhost:8080/api/values with HTTP status 200.0

I created a demo of the behavior (EDIT: fix URI) which also intercepts calls to Read() and ReadAsync() on the stream and it shows that each extra “Request ended” message occurs after a Read():

Request started: "GET" http://localhost:8080/api/values
Read[+0](, 0, 4096) = 4096
Request ended: http://localhost:8080/api/values with HTTP status 200.0
Read[+4096](, 0, 4096) = 4096
Request ended: http://localhost:8080/api/values with HTTP status 200.0
Read[+8192](, 0, 4096) = 3808
Request ended: http://localhost:8080/api/values with HTTP status 200.0
Read[+12000](, 0, 4096) = 0
Request ended: http://localhost:8080/api/values with HTTP status 200.0

I don’t know where this behavior is coming from. I’m using these versions of things:

Windows 10.0.17723 and Windows 10.0.17728
IISExpress-10.0.14358.1000

   <PackageReference Include="Microsoft.AspNet.WebApi.Owin">
      <Version>5.2.6</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Owin">
      <Version>4.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Owin.Host.SystemWeb">
      <Version>4.0.0</Version>
    </PackageReference>
    <PackageReference Include="Owin">
      <Version>1.0.0</Version>
    </PackageReference>

Also happens with Owin-3.0.x and Microsoft.AspNet.WebApi.Owin-5.2.3.

This behavior is annoying because when I serve larger files via StreamContent, the window IIS Express is running in obscures other requests and falsely reports more request ends than there actually are.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions