-
Notifications
You must be signed in to change notification settings - Fork 218
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
Controller.ControllerContext property null in AuthorizeAttributeAclModule #271
Comments
Thanks for the report. Your solution fixes the original problem, but also causes a memory leak from the circular reference. It was actually a bit of surprise to me that MVC didn't handle this detail until I realized why. I didn't put this change in the MvcContextFactory because that would cause a memory leak whenever the CreateControllerContext() method is reused somewhere else. Instead, I localized the change in the AuthorizeAttributeAclModule.VerifyContoller() method, where it could be placed in the pre-existing try-finally block to ensure it is always cleaned up. I think it is better to forget to set this property in the future than to forget to set it to null somewhere when reusing the factory and have it leak memory unknowingly. Anyway, I pushed the change to the dev branch. Please check this out for your use case to make sure it works as expected. If so, I should be able to push the patch release to NuGet tomorrow. If you need me to push it to MyGet for you so you can install it via NuGet to your project rather than building the NuGet package yourself (with build.bat - see the build instructions on the home page), let me know. |
Hi, Thanks for the quick response. I missed the memory leak. The easiest Thanks! On Tue, Feb 4, 2014 at 2:51 PM, NightOwl888 [email protected]:
Rahul B. Patel |
Hi, Thinking about it further, it seems that the GC can handle circular references just fine: http://stackoverflow.com/questions/400706/circular-references-cause-memory-leak Am I missing something in this case why the reference can't be set in MvcContextFactory? |
Hmm... I think I am getting old. I swear I read some documentation somewhere that specifically said that the CLR couldn't deal with circular references automatically. Maybe that was from an earlier version of .NET and they have since fixed it since then, I don't know. I did an experiment on the SiteMap > Node > SiteMap circular reference by removing the SiteMap.Clear() call in the SiteMapLoader and adding another 100KB of buffer onto the SiteMapNode. I also set the CacheDuration to 0. Then I watched the memory consumed by the application carefully and have confirmed that the garbage collection is working in that case - I was never able to make the MvcMusicStore consume more than about 175MB and then it would drop back down to about 100MB after doing several reloads of the SiteMap (even with the ridiculous payload I added to it). The good news is you just helped me fix the second issue in #236 (and the first issue I have fixed already and will be in the v4.5 release) because there is no reason to call the Clear() method in the first place. Anyway, I still have yet to confirm explicitly that there is no memory leak in the controller > controllerContext > controller circular reference, but I suspect my results will be the same. Thanks for pointing that out. So indeed putting this into the MvcContextFactory seems like the best choice. But it is still a puzzle why when creating a new ControllerContext object and passing it a controller why MVC doesn't automatically set the controller's ContollerContext for you. I guess that is a puzzle I don't need to solve. |
…erence was incorrect (verified by testing). Moved functionality to set the ControllerContext property of the controller to the new ControllerContext instance within the MvcContextFactory.
FYI - The fix is now live in v4.4.10. |
Hi, Thanks for all your help on this. I am going to upgrade to v4.4.10 now. I was wondering the same thing about when ControllerContext gets set in MVC On Wed, Feb 5, 2014 at 2:08 AM, NightOwl888 [email protected]:
Rahul B. Patel |
One of our custom AuthorizeAttribute implementations accesses the AuthorizationContext.Controller.ValueProvider property which is causing an ArgumentNullException inside the AuthorizeAttributeAclModule because Controller.ControllerContext property is null:
I believe either MvcContextFactory.CreateControllerContext or AuthorizeAttributeAclModule.CreateControllerContext methods should set Controller.ControllerContext property to the created ControllerContext.
Example:
The text was updated successfully, but these errors were encountered: