-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Don't hold the Target's ModuleListLock over running LoadScriptingResourceInTarget #138216
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
Conversation
…urceInTarget. That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky.
@llvm/pr-subscribers-lldb Author: None (jimingham) ChangesThat calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky. Full diff: https://github.com/llvm/llvm-project/pull/138216.diff 1 Files Affected:
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 6052cc151744d..9724039decf0d 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1046,8 +1046,14 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
bool continue_on_error) {
if (!target)
return false;
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- for (auto module : m_modules) {
+ m_modules_mutex.lock();
+ // Don't hold the module list mutex while loading the scripting resources,
+ // The initializer might do any amount of work, and having that happen while
+ // the module list is held is asking for A/B locking problems.
+ const ModuleList tmp_module_list(*this);
+ m_modules_mutex.unlock();
+
+ for (auto module : tmp_module_list.ModulesNoLocking()) {
if (module) {
Status error;
if (!module->LoadScriptingResourceInTarget(target, error,
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- lldb/source/Core/ModuleList.cpp View the diff from clang-format here.diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 9724039de..d5ddf6e84 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1052,7 +1052,7 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
// the module list is held is asking for A/B locking problems.
const ModuleList tmp_module_list(*this);
m_modules_mutex.unlock();
-
+
for (auto module : tmp_module_list.ModulesNoLocking()) {
if (module) {
Status error;
|
…urceInTarget (llvm#138216) That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky.
…urceInTarget (llvm#138216) That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky.
…urceInTarget (llvm#138216) That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky.
…urceInTarget (llvm#138216) That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky.
…urceInTarget (llvm#138216) That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble. I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky. (cherry picked from commit 0ddcd20)
That calls an unknown amount of Python code, and can do quite a bit of work - especially if people do things like launch scripted processes in this script affordance. Doing that while holding a major lock like the ModuleList lock is asking for trouble.
I tried to make a test that would actually stall without this, but I couldn't come up with anything that reliably failed. You always have to get pretty unlucky.