mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Fix deadlock in Future due to lock inversion with GIL (#58382)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/58382 Calling markCompleted on a Future now first acquires the Future's mutex (as usual) but then sometimes tries to acquire the GIL during the DataPtr extraction while still holding the Future's mutex. (This happens when the value passed to markCompleted is a Python object). This can cause a deadlock if someone else calls any of the other methods of Future while holding the GIL. There are two solutions to this: avoid holding the Future's mutex when extracting DataPtrs, and avoid holding the GIL while invoking the Future's method. In this PR I'm going for the latter, because it's a very simple immediate fix, but I believe this is brittle and that we should probably also consider the former fix. ghstack-source-id: 129105358 Test Plan: The repro in https://github.com/pytorch/pytorch/issues/58239 now doesn't deadlock. Reviewed By: mrshenli Differential Revision: D28472816 fbshipit-source-id: 1bc9bca426dd004f9eb2568db1ffd38f014450e2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eab59bae15
commit
5a238eb96e
@ -1403,7 +1403,8 @@ void initJITBindings(PyObject* module) {
|
||||
fut->wait();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>());
|
||||
|
||||
m.def("_jit_assert_is_instance", [](py::object obj, const TypePtr& type) {
|
||||
toIValue(std::move(obj), type);
|
||||
|
Reference in New Issue
Block a user