Skip to content
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

Fix memory leak bug caused by query dictionary variable params #5383

Conversation

declan-bourke
Copy link
Contributor

When invoking queries where one or more of the variable parameters is a dictionary, this causes every repeat execution of the query to add another operation result to the operation store after every completed ExecuteAsync request. This is caused by the fact that the call to GetOrAddStoredOperation in OperationStore performs a GetOrAdd on the ConcurrentDictionary<OperationRequest, IStoredOperation> _result, the .Equals equality comparison within the OperationRequest object that acts as the key and thus invoked by GetOrAdd, when comparing the content of variables will always return false with a dictionary variable because it treats it as an IEnumerable and ComparisonHelper.SequenceEqual only works for lists and not dictionaries so therefore returns false. The result is that every invocation adds another item to _results which will keep growing indefinitely, triggering a memory leak as well as higher and higher cpu usage (every time more items in _results needs to be compared to).

Co-Authored-By: davidbrazel2 47366627+davidbrazel2@users.noreply.github.com

Summary of the changes (Less than 80 chars)

  • Adds a check for the contents of a dictionary variable

Closes #5382

When invoking queries where one or more of the variable parameters is a dictionary, this causes every repeat execution of the query to add another operation result to the operation store after every completed ExecuteAsync request. This is caused by the fact that the call to GetOrAddStoredOperation in OperationStore performs a GetOrAdd on the ConcurrentDictionary<OperationRequest, IStoredOperation> _result, the .Equals equality comparison within the OperationRequest object that acts as the key and thus invoked by GetOrAdd, when comparing the content of variables will always return false with a dictionary variable because it treats it as an IEnumerable and ComparisonHelper.SequenceEqual only works for lists and not dictionaries so therefore returns false. The result is that every invocation adds another item to _results which will keep growing indefinitely, triggering a memory leak as well as higher and higher cpu usage (every time more items in _results needs to be compared to).

Co-Authored-By: davidbrazel2 <47366627+davidbrazel2@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Sep 9, 2022

CLA assistant check
All committers have signed the CLA.

@michaelstaib
Copy link
Member

@declan-bourke can you sign the CLA please.

@michaelstaib michaelstaib self-requested a review September 12, 2022 07:05
@michaelstaib michaelstaib added this to the HC-12.x.x milestone Sep 12, 2022
@declan-bourke declan-bourke removed their assignment Sep 12, 2022
@michaelstaib
Copy link
Member

I will review this tonight.

@michaelstaib michaelstaib merged commit 6ffb369 into ChilliCream:main Sep 14, 2022
@la-we
Copy link

la-we commented Nov 24, 2022

Will this be backported to v12?

@michaelstaib
Copy link
Member

michaelstaib commented Nov 29, 2022

@lweberprb we are not far off the V13 release. So, I think it's not worth it. But If you want to have a go at it you can create a PR for the main-version-12 branch and I can create a new version. Up for it?

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

Successfully merging this pull request may close these issues.

Strawberry Shake Dictionary Type Parameters Memory Leak
4 participants