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

Clears error collections on transaction end after processing. #712

Merged
merged 2 commits into from
Mar 24, 2021

Conversation

michaelgoin
Copy link
Member

@michaelgoin michaelgoin commented Mar 23, 2021

Proposed Release Notes

  • Fixed issue where capturing axios request errors could result in a memory leak.

    The agent now clears error references on transaction end, which are not used for later processing. Errors returned from 'axios' requests contain a reference to the request object which deeper down has a handle to a promise in handleRequestError. The TraceSegment associated with that promise has a handle to the transaction, which through the error capture ultimately kept the promise in memory and prevented it from being destroyed to free-up the TraceSegment from the segment map. This change also has the benefit of freeing up some memory early for transactions held onto for transaction traces.

  • Added active transaction check to wrappedResEnd to prevent unecessary work for ended transactions in the case of multiple Response.prototype.end() invocations.

Links

Details

Ideally, I'd like to avoid holding onto user errors passed-in at all. Unfortunately, this requires touching several place and doesn't play well with our duplicate error detection. The duplicate detection uses the object itself as a key to avoid situations such as an end user calling noticeError(error) on the same instance twice on accident.

It may be worth considering if that safety mechanism isn't something we want/need to keep around. I'm not sure if any other agents do similar but I don't remember anything like that from my previous team.

I'm going to submit a separate issue to dig into this further.

While this change has the benefit of also just freeing up some memory sooner... there is some risk in clearing things off the transaction as we might in the future attempt to do something with this information later after transaction end. Unlikely at this point but calling out. More likely would be haphazardly adding something that is used by transaction traces in here to clear out as well.

This avoids memory leaks due to promise handles attached to errors and allows freeing up some memory early for transactions held for transaction traces.
@michaelgoin michaelgoin added risk: low This change does not impact critical areas of the code and is expected to have minimal risk. semver: patch Backwards compatible fixes. labels Mar 23, 2021
@michaelgoin michaelgoin added risk: medium This change impacts senstive areas or has other traits that warrant more careful consideration. and removed risk: low This change does not impact critical areas of the code and is expected to have minimal risk. labels Mar 23, 2021
Copy link
Contributor

@carlo-808 carlo-808 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, we are clearing transaction user errors and exceptions on transaction end. 👍

@carlo-808 carlo-808 merged commit be351c6 into newrelic:main Mar 24, 2021
@github-actions github-actions bot mentioned this pull request Mar 29, 2021
@michaelgoin michaelgoin deleted the clear-error-refs branch November 5, 2021 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
risk: medium This change impacts senstive areas or has other traits that warrant more careful consideration. semver: patch Backwards compatible fixes.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Agent introduces memory leak when axios errors noticed
2 participants