V10: Fix request accessor memory leak#13152
Merged
nikolajlauridsen merged 3 commits intov10/devfrom Oct 13, 2022
Merged
Conversation
Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called.
kjac
approved these changes
Oct 12, 2022
Contributor
kjac
left a comment
There was a problem hiding this comment.
@nikolajlauridsen lovely 😄 make the new handler internal and the new EnsureApplicationUrl() method likewise as we just discussed, then it's all good 👍
nikolajlauridsen
added a commit
that referenced
this pull request
Oct 13, 2022
* Dispose OnChange event registration when disposing the notification handler * Ensure that the ApplicationUrl is only initialized once Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called. * Make notification handler and EnsureApplicationUrl internal
Zeegaan
added a commit
that referenced
this pull request
Oct 13, 2022
* Fix for potential race condition in packages search (#13153) * search on input allowing to wait for copy/paste etc * invoke resourcePromise() with correct parameters * return the xhrStatus allowing the caller to check if the request was aborted * fix: send in canceler.promise to allow the timeout to work * catch any errors and ignore aborts if they happen * move the logic to handle cancellations outside Angulars $scope.$apply * remove file accidentally committed * V10: Fix request accessor memory leak (#13152) * Dispose OnChange event registration when disposing the notification handler * Ensure that the ApplicationUrl is only initialized once Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called. * Make notification handler and EnsureApplicationUrl internal * Add missing ForceLeft and ForceRight (#13190) * Fix tags with CSV storage type (#13188) * Fixing null check as default(NRT) is null => default(configuration?.Delimiter) is also null and we were counting on it being the same as default(char) * Adding tests to check cases with multiple tags (or tag made of comma separated values) * Add data-element to umb property so we can find it (#13199) Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: Zeegaan <nge@umbraco.dk>
Zeegaan
added a commit
that referenced
this pull request
Oct 13, 2022
* Fix for potential race condition in packages search (#13153) * search on input allowing to wait for copy/paste etc * invoke resourcePromise() with correct parameters * return the xhrStatus allowing the caller to check if the request was aborted * fix: send in canceler.promise to allow the timeout to work * catch any errors and ignore aborts if they happen * move the logic to handle cancellations outside Angulars $scope.$apply * remove file accidentally committed * V10: Fix request accessor memory leak (#13152) * Dispose OnChange event registration when disposing the notification handler * Ensure that the ApplicationUrl is only initialized once Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called. * Make notification handler and EnsureApplicationUrl internal * Add missing ForceLeft and ForceRight (#13190) * Fix tags with CSV storage type (#13188) * Fixing null check as default(NRT) is null => default(configuration?.Delimiter) is also null and we were counting on it being the same as default(char) * Adding tests to check cases with multiple tags (or tag made of comma separated values) * Add data-element to umb property so we can find it (#13199) Co-authored-by: Zeegaan <nge@umbraco.dk> * V10/bugfix/create simple package test (#13162) * Fixed assert to hopefully find the package each time so it isnt flaky anymore * Updated so it retries 5 times instead of 2 * Dont submit html-report * Dont have output defined in npm run * Copy over playwright trace.zip files before publishing * Updated assert so it looks after the package in the table * updated so we get the first fail as the trace file * Bumped version for testhelpers * Updated so the test checks if the package actually exists. Added a wait that checks if the created packages button is visible * Updated package lock * Fixed so it now calls the correct testhelper Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Andreas Zerbst <73799582+andr317c@users.noreply.github.com>
elit0451
added a commit
that referenced
this pull request
Oct 18, 2022
* Add null check * Fix for potential race condition in packages search (#13153) * search on input allowing to wait for copy/paste etc * invoke resourcePromise() with correct parameters * return the xhrStatus allowing the caller to check if the request was aborted * fix: send in canceler.promise to allow the timeout to work * catch any errors and ignore aborts if they happen * move the logic to handle cancellations outside Angulars $scope.$apply * remove file accidentally committed * V10: Fix request accessor memory leak (#13152) * Dispose OnChange event registration when disposing the notification handler * Ensure that the ApplicationUrl is only initialized once Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called. * Make notification handler and EnsureApplicationUrl internal * Add missing ForceLeft and ForceRight (#13190) * Fix tags with CSV storage type (#13188) * Fixing null check as default(NRT) is null => default(configuration?.Delimiter) is also null and we were counting on it being the same as default(char) * Adding tests to check cases with multiple tags (or tag made of comma separated values) * Add data-element to umb property so we can find it (#13199) Co-authored-by: Zeegaan <nge@umbraco.dk> * V10/bugfix/create simple package test (#13162) * Fixed assert to hopefully find the package each time so it isnt flaky anymore * Updated so it retries 5 times instead of 2 * Dont submit html-report * Dont have output defined in npm run * Copy over playwright trace.zip files before publishing * Updated assert so it looks after the package in the table * updated so we get the first fail as the trace file * Bumped version for testhelpers * Updated so the test checks if the package actually exists. Added a wait that checks if the created packages button is visible * Updated package lock * Fixed so it now calls the correct testhelper Co-authored-by: Zeegaan <nge@umbraco.dk> * Update src/Umbraco.Core/PropertyEditors/DataValueEditor.cs Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: Andreas Zerbst <73799582+andr317c@users.noreply.github.com> Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>
nikolajlauridsen
added a commit
that referenced
this pull request
Oct 19, 2022
* Fix broken selectable state for list view items (#13148) * Add sync rendering extensions for block grid and async ones for block list (#13168) * Re-add IsPackable to Umbraco.Tests.Integration * Fix for potential race condition in packages search (#13153) * search on input allowing to wait for copy/paste etc * invoke resourcePromise() with correct parameters * return the xhrStatus allowing the caller to check if the request was aborted * fix: send in canceler.promise to allow the timeout to work * catch any errors and ignore aborts if they happen * move the logic to handle cancellations outside Angulars $scope.$apply * remove file accidentally committed * Fix for potential race condition in packages search (#13153) * search on input allowing to wait for copy/paste etc * invoke resourcePromise() with correct parameters * return the xhrStatus allowing the caller to check if the request was aborted * fix: send in canceler.promise to allow the timeout to work * catch any errors and ignore aborts if they happen * move the logic to handle cancellations outside Angulars $scope.$apply * remove file accidentally committed (cherry picked from commit 4a412bb) * V10: Fix request accessor memory leak (#13152) * Dispose OnChange event registration when disposing the notification handler * Ensure that the ApplicationUrl is only initialized once Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called. * Make notification handler and EnsureApplicationUrl internal * Add missing ForceLeft and ForceRight (#13190) * V10: Fix request accessor memory leak (#13152) * Dispose OnChange event registration when disposing the notification handler * Ensure that the ApplicationUrl is only initialized once Since notifications handlers are transient,_hasAppUrl and _isInit defaults to false on every request causing it to always be called. * Make notification handler and EnsureApplicationUrl internal * Add missing ForceLeft and ForceRight (#13190) * Pass the node property to umb-property & umb-property-editor (#13151) Co-authored-by: Zeegaan <nge@umbraco.dk> * V10: 13099 fix validation error (#13170) * Add validation error message to Viewpicker * Add help-inline class to make validation-text red Co-authored-by: Zeegaan <nge@umbraco.dk> * move clear:both; to the flexbox example (#13194) * remove pointer-events from Image, to make drag n' drop work on firefox. (#13193) * area permission min-max inputs width increase (#13195) * Fix tags with CSV storage type (#13188) * Fixing null check as default(NRT) is null => default(configuration?.Delimiter) is also null and we were counting on it being the same as default(char) * Adding tests to check cases with multiple tags (or tag made of comma separated values) * Fix tags with CSV storage type (#13188) * Fixing null check as default(NRT) is null => default(configuration?.Delimiter) is also null and we were counting on it being the same as default(char) * Adding tests to check cases with multiple tags (or tag made of comma separated values) * Add documentation for default block grid partial views in the rendering extension methods (#13184) * Add data-element to umb property so we can find it (#13199) Co-authored-by: Zeegaan <nge@umbraco.dk> * Add data-element to umb property so we can find it (#13199) Co-authored-by: Zeegaan <nge@umbraco.dk> * V10/bugfix/create simple package test (#13162) * Fixed assert to hopefully find the package each time so it isnt flaky anymore * Updated so it retries 5 times instead of 2 * Dont submit html-report * Dont have output defined in npm run * Copy over playwright trace.zip files before publishing * Updated assert so it looks after the package in the table * updated so we get the first fail as the trace file * Bumped version for testhelpers * Updated so the test checks if the package actually exists. Added a wait that checks if the created packages button is visible * Updated package lock * Fixed so it now calls the correct testhelper Co-authored-by: Zeegaan <nge@umbraco.dk> * Merge BjarneF fix into 10.3 (#13220) Co-authored-by: Bjarne Fyrstenborg <bjarne_fyrstenborg@hotmail.com> * make Area fit within block row (#13221) * 10.3.0-RC: Change grid area input to number + change generic label (#13203) Co-authored-by: Bjarne Fyrstenborg <bjarne_fyrstenborg@hotmail.com> * move below center, to make room (#13222) * highlight areas in dragging-mode for modern browsers (#13224) * Collect new .xml language files from different sources (#13212) * Collecting new language files from different sources * Apply suggestions from review * Adding TODO for merging the language files locations to one when packages are not concerned * Collect new .xml language files from different sources (#13212) * Collecting new language files from different sources * Apply suggestions from review * Adding TODO for merging the language files locations to one when packages are not concerned * Resync editors if content model changed (#13230) * Disable BlockGridEditor (#13229) * Disable BlockGridEditor * Fix typeloader test * Update src/Umbraco.Core/Models/Blocks/BlockGridItem.cs Co-authored-by: Kenn Jacobsen <kja@umbraco.dk> * Apply suggestions from code review Co-authored-by: Kenn Jacobsen <kja@umbraco.dk> Co-authored-by: Kenn Jacobsen <kja@umbraco.dk> * V10.4: Re-enable block grid editor (#13231) * Revert "Disable BlockGridEditor (#13229)" This reverts commit 4e9aa8d. * Re-do xml comments fix * Fix nullable reference error * Fix acceptance test package.json and package-lock.json * Re-add wait-on Co-authored-by: Kenn Jacobsen <kja@umbraco.dk> Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: Andreas Zerbst <73799582+andr317c@users.noreply.github.com> Co-authored-by: Bjarne Fyrstenborg <bjarne_fyrstenborg@hotmail.com> Co-authored-by: Matt Darby <matt@darby.digital>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #13098.
As described in the issue there was a memory leak in
AspNetCoreRequestAccessorThe reason for this memory leak was that it was set up as a notification handler, which is transient. This meant that every time a request was sent, a new
AspNetCoreRequestAccessorwas initialized, and an OnChange even registered on theIOptionsMonitor, this meant that theAspNetCoreRequestAccessoralongside its delegate in theIOptionsMonitorwould never be GC'ed.To add insult to injury, since the notification handler is transient, the
_isInitand_hasAppUrlwould re-default to false each time, meaning thatGetApplicationUrlis called unnecessarily on every request.Unfortunately, this is not that simple to fix in a nice way without breaking changes. What I've done is implement
IDisposableon theAspNetCoreRequestAccessor, this allows us to unregister ourOnChangewhen disposing notification handler, meaning no more hanging references 🎉.Additionally to fix the initializer issue I've created a new class
ApplicationUrlRequestBeginNotificationHandlerwhich then calls theEnsureApplicationUrl, making sure we're using the singleton instance ofAspNetCoreRequestAccessor.Testing
I've tested in this way, and everything seems to be working great.
AspNetCoreRequestAccessorsin memoryGetApplicationUrlis only called once, not on every request.These was my results:
v10/dev dev after sending ~32k requests:

This branch after sending ~34K requests:
As you can see, prior to this branch we'd have ~32K instances of
AspNetCoreRequestAccessorin memory, on this branch, there are none.