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

[release/6.0] Fix memory leak in enqueue/dequeue of EventPipe callback data. #58244

Merged
merged 2 commits into from
Aug 27, 2021

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 27, 2021

Backport of #58170 to release/6.0

/cc @lateralusX

Customer Impact

Small memory leak on each EventSource EventPipe provider enable/disable callback invocation introduced by #56104. Leak size is size of callback filter_data on enable and disable. Filter data is not used in all scenarios and for cases where filter data is not used nothing will be leaked. NOTE, memory leak affects both CoreCLR as well as Mono.

Testing

We have native EventPipe tests that can be run with automatic memory leak detection in debug build. It is currently not automated, so needs to be run manually (that's how this memory leak was found), https://github.com/dotnet/runtime/tree/main/src/mono/mono/eventpipe/test.

Risk

Low. Since the leak is small it can be discussed if we should leave it as is. Filter data can however be passed over our diagnostic IPC protocol when starting a session, so it is possible to trigger this memory leak over IPC.

#56104 made sure provider
callback data gets its own copy of filter data. This created a couple
of memory leaks when queue/dequeue the callback data since callback data
was not correctly freed in these scenarios leading to leaks of the copied
filter data.

Was detected running the manual EventPipe native unit tests on Windows
using its build in use of _CrtMemCheckpoint (only available in debug
builds) automatically detecting memory leaks.

Fix makes sure callback data is moved into queue on enqueue and moved
out in dequeue and that caller of dequeue make sure to
free returned callback data using ep_provider_callback_data_fini
when done using it. Doing a move instead of copy will also reduce
the number of allocations when enqueue/dequeue callback data in
provider callback queue.
@marek-safar marek-safar added Servicing-consider Issue for next servicing release review Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Aug 27, 2021
@lateralusX
Copy link
Member

//CC @josalem, backport to net6.

@Anipik Anipik merged commit 59f5157 into release/6.0 Aug 27, 2021
@akoeplinger akoeplinger deleted the backport/pr-58170-to-release/6.0 branch August 28, 2021 22:03
@ghost ghost locked as resolved and limited conversation to collaborators Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tracing-mono Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants