◐ Shell
clean mode source ↗

gh-149816: Fix race condition in `memoryview` with free-threading by sobolevn · Pull Request #149858 · python/cpython

» ./python.exe /Users/sobolev/Desktop/cpython-ft/repros/132.py         
finding: 132 memoryview.hex() export/release race
expected signal: memoryview.release() unexpectedly succeeds inside sep.__len__, or native crash/sanitizer report
parameters: seconds=30; GIL=disabled (free-threaded build); size=1048576; hexers=6; exporters=12; len_yields=1
------------------------------------------------------------------------
Exception in thread hex-1:
Fatal Python error: Segmentation fault

<Cannot show all threads while the GIL is disabled>
Stack (most recent call first):
  File "/Users/sobolev/Desktop/cpython-ft/repros/132.py", line 152 in hex_worker
  File "/Users/sobolev/Desktop/cpython/Lib/threading.py", line 1160 in run
  File "/Users/sobolev/Desktop/cpython/Lib/threading.py", line 1218 in _bootstrap_inner
  File "/Users/sobolev/Desktop/cpython/Lib/threading.py", line 1180 in _bootstrap

Current thread's C stack trace (most recent call first):
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _Py_DumpStack+0x44 [0x105012b3c]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at faulthandler_fatal_error+0x240 [0x105034d74]
  Binary file "/usr/lib/system/libsystem_platform.dylib", at _sigtramp+0x38 [0x19ce6d6a4]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _Py_strhex_impl+0x170 [0x105017858]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at memoryview_hex+0x1d8 [0x104e19fa8]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyCallMethodDescriptorFastWithKeywords_StackRef+0xcc [0x104f26100]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyEval_EvalFrameDefault+0x82a4 [0x104f2eda8]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyEval_Vector+0x340 [0x104f2511c]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyObject_VectorcallTstate+0x6c [0x104d9d318]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyObject_VectorcallPrepend+0xec [0x104d9f3b0]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at context_run+0xa4 [0x104f697d0]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyObject_VectorcallTstate+0x6c [0x104d9d318]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _Py_VectorCallInstrumentation_StackRefSteal+0x11c [0x104f25830]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyEval_EvalFrameDefault+0x4020 [0x104f2ab24]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyEval_Vector+0x340 [0x104f2511c]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyObject_VectorcallTstate+0x6c [0x104d9d318]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at _PyObject_VectorcallPrepend+0xec [0x104d9f3b0]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at thread_run+0x84 [0x1050ace48]
  Binary file "/Users/sobolev/Desktop/cpython/python.exe", at pythread_wrapper+0x1c [0x10500f810]
  Binary file "/usr/lib/system/libsystem_pthread.dylib", at _pthread_start+0x88 [0x19ce33c0c]
  Binary file "/usr/lib/system/libsystem_pthread.dylib", at thread_start+0x8 [0x19ce2eb80]
[1]    88946 segmentation fault  ./python.exe /Users/sobolev/Desktop/cpython-ft/repros/132.py

After: code snippet passes.
I am not really sure that there's an easy and predictable way to trigger this error without going really deep into implementation details and making a test too fragile.