Quirk with MapMiddleware when exception propagates outside of the branch #510
Description
Here is a sample project:
https://github.com/tuespetre/aspnet-map-quirk
The issue may be reproduced with that project with the following steps:
- Run the application, using either
dnx web
or the IIS Express option from Visual Studio - Load the page in the browser
- Click the button to send a request to the page that will raise an exception
- Send further GET requests to the page
The symptom is that, after having raised the exception, the PathBase
of the request will be intermittently doubled up, resulting in broken links. Having stepped through the MapMiddleware
's Invoke
method, I can see that the context.Request.PathBase
is already set to /aspnet-map-quirk
coming into the middleware, even though the request URI shows properly as /aspnet-map-quirk
when inspecting the Features
collection on the HttpContext.
I am not sure if this is due to faulty context recycling on part of Kestrel or not, as I don't know much about Kestrel -- perhaps @davidfowl or @DamianEdwards would have something to say here.
The workaround is to uncomment the following line:
https://github.com/tuespetre/aspnet-map-quirk/blob/master/AspNetMapQuirk/Startup.cs#L21
This prevents the exception from propagating out of the branch and subsequently causing the issue with the doubled-up PathBase
.
A try ... finally
block within MapMiddleware
's Invoke
method would ultimately guard against this issue.