-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Don't re-use DefaultHttpContext if IHttpContextAccessor is in use #15049
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
Conversation
- Consumers may still get null or an ODE but will never end up with data from a different request. - Make sure an ODE is thrown from all properties on HttpContext after the request is over.
using Moq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Hosting.Tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't new but I renamed files (my bad).
- HostingApplicationDiagnosticsTests used to be HostingApplicationTests
- HostingApplicationTests contain the new tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I uses git mv
to ensure it git picks up file renames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's nice :)
@anurse, this is something we should patch in the 3.1 timeframe |
Who approved this for 3.1? |
@anurse nobody, it's in master |
Horp, missed that. Sorry! :) |
I still think we should backport this to 3.1. I'll open an issue (or can I just do a PR?) |
PR is fine. |
…5049) * Don't re-use DefaultHttpContext if IHttpContextAccessor is in use - Consumers may still get null or an ODE but will never end up with data from a different request. - Make sure an ODE is thrown from all properties on HttpContext after the request is over.
If possible, this should be backported to 2.1 and 2.2 as soon as possible. It pottentially can cause serious issues to existing applications with wrong impersonation. |
This never existed on 2.2 and 2.1 that’s a different issue. |
@davidfowl I created this demonstration based on the code that you posted in #14975. Is my test wrong? If it is correct, does this actually happens in 3.1.5? |
Just a clarification. I cannot reproduce the data race issue with HttpContext in asp.net core 2.2. But it does occur with all versions of 2.1. |
@ldwedari This is using IIS or Kestrel? |
@davidfowl Kestrel. In fact, in my test I removed the IIS configuration from launchsettings.json. |
I had to dig into the code archives to remember the 2.1 behavior. In 2.1 we never cleared the HttpContext state after the request is over which means its entirely possible to get values from the next request since the HttpContext points to the same feature collection when using Kestrel on the same connection. This isn't related to the |
Fixes #14975
cc @benaadams