Destructor of vtkDataEncoder hangs with apparent deadlock
This issue was cut down from a problem with the Mayavi package. With the Python "vtk" package, I'm able to easily hang the process simply by creating vtkDataEncoder
instances and then allowing them to be garbage collected.
The following simple script hangs for me on macOS 10.15.7 on an Intel MacBook Pro, Python 3.9.7, vtk 9.0.3:
import vtk
print("Version:", vtk.VTK_VERSION)
print("Starting loop")
for _ in range(100):
vtk.vtkDataEncoder()
print("Finished")
The output is just:
(mayavi) mdickinson@mirzakhani Desktop % python vtk_bug.py
Version: 9.0.3
Starting loop
Attaching lldb to the hanging process shows that it's locked at the point where it's trying to tear down the thread pool:
mdickinson@mirzakhani ~ % lldb -p 6292
(lldb) process attach --pid 6292
Process 6292 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x00007fff70dad55e libsystem_kernel.dylib`__ulock_wait + 10
libsystem_kernel.dylib`__ulock_wait:
-> 0x7fff70dad55e <+10>: jae 0x7fff70dad568 ; <+20>
0x7fff70dad560 <+12>: movq %rax, %rdi
0x7fff70dad563 <+15>: jmp 0x7fff70dac629 ; cerror_nocancel
0x7fff70dad568 <+20>: retq
Target 0: (Python) stopped.
Executable module set to "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python".
Architecture set to: x86_64h-apple-macosx-.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
* frame #0: 0x00007fff70dad55e libsystem_kernel.dylib`__ulock_wait + 10
frame #1: 0x00007fff70e705c2 libsystem_pthread.dylib`_pthread_join + 347
frame #2: 0x000000010a4f28a2 libvtkCommonCore-9.0.dylib`vtkMultiThreader::TerminateThread(int) + 226
frame #3: 0x000000010a8845cc libvtkWebCore-9.0.dylib`vtkDataEncoder::vtkInternals::TerminateAllWorkers() + 124
frame #4: 0x000000010a88467d libvtkWebCore-9.0.dylib`vtkDataEncoder::~vtkDataEncoder() + 29
frame #5: 0x000000010a283e3d libvtkWrappingPythonCore-9.0.dylib`vtkPythonUtil::RemoveObjectFromMap(_object*) + 157
frame #6: 0x000000010a268215 libvtkWrappingPythonCore-9.0.dylib`PyVTKObject_Delete + 37
frame #7: 0x000000010980fb57 Python`_PyEval_EvalFrameDefault + 2263
frame #8: 0x0000000109818be2 Python`_PyEval_EvalCode + 2008
frame #9: 0x000000010980f1c8 Python`PyEval_EvalCode + 57
frame #10: 0x000000010984a059 Python`run_eval_code_obj + 110
frame #11: 0x0000000109849230 Python`run_mod + 103
frame #12: 0x00000001098493ae Python`pyrun_file + 216
frame #13: 0x0000000109847a4e Python`PyRun_SimpleFileExFlags + 660
frame #14: 0x000000010985f7c7 Python`Py_RunMain + 1839
frame #15: 0x000000010985fb36 Python`pymain_main + 360
frame #16: 0x000000010985fb8b Python`Py_BytesMain + 42
frame #17: 0x00007fff70c6acc9 libdyld.dylib`start + 1
frame #18: 0x00007fff70c6acc9 libdyld.dylib`start + 1