Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

AspNetCoreModule throws 500 error for requests that specify relative quality in the Accept header #262

Closed
videege opened this issue Sep 15, 2016 · 5 comments

Comments

@videege
Copy link

videege commented Sep 15, 2016

IIS & IIS Express return a 500.0 response for a request that specifies a q=# in the Accept header

Functional impact

Causes all requests to fail mysteriously with a 500 response generated by the AspNetCoreModule.

Minimal repro steps

Finally found this cause of some mysterious 500 errors we were seeing in our APIs. If you specify an Accept header to any API request, such as:

text/html, *; q=.2, */*; q=.2

The AspNetCoreModule will fail with a 500 error.

To reproduce this in IIS or IIS express:

  1. Create a new ASP.NET Core web application.
  2. Create an API controller (such as the default ValuesController).
  3. Send a request with an Accept header including the relative quality factor.

Important: This bug does not appear in .NET Core applications running under RC1 (which I believe uses a different IIS module).

Expected result

The request should succeed.

Actual result

The request returns a non-descript 500.0 error: IIS failed request trace logging reveals this:

ModuleName
AspNetCoreModule
Notification
EXECUTE_REQUEST_HANDLER
HttpStatus
500
HttpReason
Internal Server Error
HttpSubStatus
0
ErrorCode
The operation completed successfully.
(0x0)
ConfigExceptionInfo

@Tratcher
Copy link
Member

What makes you think this is an AspNetCoreModule issue? Does it reproduce if you run Kestrel independently?

@videege
Copy link
Author

videege commented Sep 15, 2016

To be honest, I'm not sure - it could be a Kestrel issue (I will run some tests now). I assumed it was the module issue because I don't see the error with RC1 apps running under the HttpPlatformHandler module. Also, this error appears to occur before any application or Kestrel code is invoked.

@videege
Copy link
Author

videege commented Sep 15, 2016

Well, it looks like you're right. Running directly under Kestrel I can see that the error is in there:

Activated   Event   Time    Duration    Thread
    Microsoft.AspNetCore.Server.Kestrel:Error: Connection id "0HKUTHDTJVDPJ": An unhandled exception was thrown by the application.

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: length
   at Microsoft.Extensions.Primitives.StringSegment..ctor(String buffer, Int32 offset, Int32 length)
   at Microsoft.AspNetCore.Mvc.Formatters.MediaType.CreateMediaTypeSegmentWithQuality(String mediaType, Int32 start)
   at Microsoft.AspNetCore.Mvc.Formatters.Internal.AcceptHeaderParser.GetMediaTypeWithQualityLength(String input, Int32 start, MediaTypeSegmentWithQuality& result)
   at Microsoft.AspNetCore.Mvc.Formatters.Internal.AcceptHeaderParser.TryParseValue(String value, Int32& index, MediaTypeSegmentWithQuality& parsedValue)
   at Microsoft.AspNetCore.Mvc.Formatters.Internal.AcceptHeaderParser.ParseAcceptHeader(IList`1 acceptHeaders, IList`1 parsedValues)
   at Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor.GetAcceptableMediaTypes(MediaTypeCollection contentTypes, HttpRequest request)
   at Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor.SelectFormatter(OutputFormatterWriteContext formatterContext, MediaTypeCollection contentTypes, IList`1 formatters)
   at Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor.ExecuteAsync(ActionContext context, ObjectResult result)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultFilterAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAllResultFiltersAsync>d__29.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResourceFilterAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.ApplicationInsights.AspNetCore.ExceptionTrackingMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.ApplicationInsights.AspNetCore.RequestTrackingMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.Compile    9.53s

Seems like you should get a better error than 500.0 though, right?

@videege
Copy link
Author

videege commented Sep 15, 2016

Sorry, looks like I should be filing an issue in the Mvc repo. Thanks for pointing me in the right direction.

@videege videege closed this as completed Sep 15, 2016
@Tratcher
Copy link
Member

Looks like a duplicate of aspnet/Mvc#5150

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants