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] [Mono]: Potential deadlock during EventPipe rundown using interpreter. #59023

Merged
merged 1 commit into from
Sep 13, 2021

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 13, 2021

Backport of #58996 to release/6.0

/cc @marek-safar @lateralusX

Customer Impact

Possible deadlock during rundown (ending EventPipe session) when running on MonoVM using interpreter.

Testing

Issue hit by CI on main branch.

Risk

Low

Identified deadlock between finalizer thread and rundown enumerating
all interpreter method. Since rundown will query for method name
in callback when iterating interpreter methods, interp_jit_info_foreach,
that might lead to additional loader activity. The hash map in
interpreter keeping the methods is locked with default JIT memory manager,
but since the callback might end up in mono_class_create_from_typedef
that will take loader lock, we get the following lock order on that
code path, memory manager->loader lock. Finalizer thread invokes
OnThreadExiting using interpreter and that might end up with a reverse
lock order, loader lock->memory manager on that code path, so these
two have a potential to deadlock. This is not a problem under JIT
or AOT since the JIT hash table is lock free therefore not causing
any deadlocks due to lock order between memory manager and loader lock.

Could be fixed by changing into a lock free hash table in interpreters
for interp_code_hash might be to risky at this point. A more safe fix
is to take a copy of the pointers while holding lock and then iterate
using local copy (simple array of pointers). Since this method is
only called during rundown, only when using interpreter, and only
include the pointers (InterpMethod *) we use with the callback,
it will have some temporary memory impact (allocating an array
of pointers), but will mitigate the deadlock since we can safely
call iterator callback without holding the lock. It will also
improve interpreter performance in situations where we run session
rundown, since lock will be held a much shorter amount of time.
@ghost
Copy link

ghost commented Sep 13, 2021

Tagging subscribers to this area: @BrzVlad
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #58996 to release/6.0

/cc @marek-safar @lateralusX

Customer Impact

Testing

Risk

Author: github-actions[bot]
Assignees: -
Labels:

area-Codegen-Interpreter-mono

Milestone: -

@Anipik Anipik merged commit 8b70244 into release/6.0 Sep 13, 2021
@jkotas jkotas deleted the backport/pr-58996-to-release/6.0 branch September 18, 2021 04:09
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants