Closed scott-xu closed 2 years ago
Thanks for the report. I don't see a reason why we couldn't use a different lock in PythonContext.DeleteIndex
(as well as in GetIndex
and SetIndex
). Do you have a code sample code that could be used to reproduce the issue so I can set up a unit test?
Here's the sample code.
import xml.etree.ElementTree as ET
s = '<Data>' + ('1'*8192) + '</Data>'
elem = ET.fromstring(s)
result_len = len(ET.tostring(elem))
string_len = len(s)
result = str(result_len == string_len)
Thanks, was able to reproduce the deadlock with code like this:
var code = @"
import xml.etree.ElementTree as ET
s = '<Data>' + ('1'*8192) + '</Data>'
elem = ET.fromstring(s)
ET.tostring(elem)";
// retry to increase chance of deadlock
for (var i = 0; i < 100; i++) {
Console.WriteLine(i);
ScriptEngine eng = Python.CreateEngine();
eng.SetSearchPaths(new List<string> { pathToLib });
await Task.Run(() => eng.Execute(code));
}
Thanks for the quick fix! Will the fix be included in 3.4 final release? It has been half a year since 3.4 beta1. When do you think 3.4 final would be ready?
Thanks for the quick fix! Will the fix be included in 3.4 final release? It has been half a year since 3.4 beta1. When do you think 3.4 final would be ready?
Yes it will be in the final release which should be ready soon (yes, I know I've been saying that for a while). I just need to find some time to finish up https://github.com/IronLanguages/ironpython3/pull/1598, package DLR and IronPython and then test the packages.
Perfect! Thanks for the great work!
Description
A worker thread is calling
PythonContext.CreateBuiltinModule
which locksPythonContext
. Then it will callFunctionCode.LazyCompileFirstTarget
where it tries to acquire_CodeCreateAndUpdateDelegateLock
PythonContext.cs
FunctionCode.cs
A GC thread is executing the
WeakRef
's finalizer which callsFunctionCode.LazyCompileFirstTarget
and locks_CodeCreateAndUpdateDelegateLock
, then it will callPythonContext.DeleteIndex
where it tries to acquirePythonContext
.PythonContext.cs
Worker Thread
. . .
GC Thread