Skip to content
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

Race between PyUnicode_SET_UTF8 and _PyUnicode_CheckConsistency #128212

Open
mpage opened this issue Dec 24, 2024 · 2 comments
Open

Race between PyUnicode_SET_UTF8 and _PyUnicode_CheckConsistency #128212

mpage opened this issue Dec 24, 2024 · 2 comments
Labels
topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@mpage
Copy link
Contributor

mpage commented Dec 24, 2024

Bug report

Bug description:

Reproducible by running :

  1. env CC=clang CXX=clang++ ./configure --disable-gil --with-thread-sanitizer --with-pydebug && make -j
  2. env TSAN_OPTIONS=suppressions=${PWD}/Tools/tsan/suppressions_free_threading.txt ./python -m test --tsan test_importlib --match test_multiprocessing_pool_circular_import -F
==================
WARNING: ThreadSanitizer: data race (pid=3454844)
  Atomic write of size 8 at 0x7fd7be2285d0 by thread T1:
    #0 _Py_atomic_store_ptr_release /home/mpage/local/cpython/./Include/cpython/pyatomic_gcc.h:565:3 (python+0x74072e) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #1 PyUnicode_SET_UTF8 /home/mpage/local/cpython/Objects/unicodeobject.c:133:5 (python+0x74072e)
    #2 unicode_fill_utf8 /home/mpage/local/cpython/Objects/unicodeobject.c:5916:5 (python+0x74072e)
    #3 unicode_ensure_utf8 /home/mpage/local/cpython/Objects/unicodeobject.c:4228:19 (python+0x74072e)
    #4 PyUnicode_AsUTF8AndSize /home/mpage/local/cpython/Objects/unicodeobject.c:4246:9 (python+0x74072e)
    #5 write_unicode_binary /home/mpage/local/cpython/./Modules/_pickle.c:2677:12 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xa219) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #6 save_unicode /home/mpage/local/cpython/./Modules/_pickle.c:2729:13 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xa219)
    #7 save /home/mpage/local/cpython/./Modules/_pickle.c:4392:16 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x940a) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #8 batch_dict_exact /home/mpage/local/cpython/./Modules/_pickle.c:3346:17 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xb682) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #9 save_dict /home/mpage/local/cpython/./Modules/_pickle.c:3408:22 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xb682)
    #10 save /home/mpage/local/cpython/./Modules/_pickle.c:4402:18 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x9624) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #11 dump /home/mpage/local/cpython/./Modules/_pickle.c:4602:9 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x8068) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #12 _pickle_Pickler_dump_impl /home/mpage/local/cpython/./Modules/_pickle.c:4676:9 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x21a74) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #13 _pickle_Pickler_dump /home/mpage/local/cpython/./Modules/clinic/_pickle.c.h:73:20 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x21a74)
    #14 cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD /home/mpage/local/cpython/Objects/methodobject.c:468:24 (python+0x6924c6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #15 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:167:11 (python+0x5d48f0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #16 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #17 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:960:35 (python+0x8291e2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #18 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #19 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #20 _PyFunction_Vectorcall /home/mpage/local/cpython/Objects/call.c (python+0x5d6799) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #21 _PyObject_VectorcallDictTstate /home/mpage/local/cpython/Objects/call.c:135:15 (python+0x5d4b88) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #22 _PyObject_Call_Prepend /home/mpage/local/cpython/Objects/call.c:504:24 (python+0x5d6bd2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #23 slot_tp_init /home/mpage/local/cpython/Objects/typeobject.c:10233:15 (python+0x71d085) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #24 type_call /home/mpage/local/cpython/Objects/typeobject.c:2185:19 (python+0x6fd01c) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #25 _PyObject_MakeTpCall /home/mpage/local/cpython/Objects/call.c:242:18 (python+0x5d4fd1) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #26 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:165:16 (python+0x5d4918) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #27 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #28 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:960:35 (python+0x8291e2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #29 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #30 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #31 _PyFunction_Vectorcall /home/mpage/local/cpython/Objects/call.c (python+0x5d6799) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #32 _PyObject_VectorcallDictTstate /home/mpage/local/cpython/Objects/call.c:146:15 (python+0x5d4b64) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #33 _PyObject_Call_Prepend /home/mpage/local/cpython/Objects/call.c:504:24 (python+0x5d6bd2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #34 slot_tp_init /home/mpage/local/cpython/Objects/typeobject.c:10233:15 (python+0x71d085) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #35 type_call /home/mpage/local/cpython/Objects/typeobject.c:2185:19 (python+0x6fd01c) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #36 _PyObject_MakeTpCall /home/mpage/local/cpython/Objects/call.c:242:18 (python+0x5d4fd1) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #37 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:165:16 (python+0x5d4918) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #38 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #39 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:1993:35 (python+0x8310ad) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #40 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #41 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #42 _PyFunction_Vectorcall /home/mpage/local/cpython/Objects/call.c (python+0x5d6799) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #43 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:167:11 (python+0x5dc820) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #44 method_vectorcall /home/mpage/local/cpython/Objects/classobject.c:71:20 (python+0x5dae9d) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #45 _PyVectorcall_Call /home/mpage/local/cpython/Objects/call.c:273:16 (python+0x5d619d) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #46 _PyObject_Call /home/mpage/local/cpython/Objects/call.c:348:16 (python+0x5d6413) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #47 PyObject_Call /home/mpage/local/cpython/Objects/call.c:373:12 (python+0x5d65c7) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #48 thread_run /home/mpage/local/cpython/./Modules/_threadmodule.c:346:21 (python+0xa28898) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #49 pythread_wrapper /home/mpage/local/cpython/Python/thread_pthread.h:242:5 (python+0x96a4bb) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)

  Previous read of size 8 at 0x7fd7be2285d0 by thread T18:
    #0 _PyUnicode_CheckConsistency /home/mpage/local/cpython/Objects/unicodeobject.c:691:13 (python+0x72f906) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #1 PyUnicode_UTF8 /home/mpage/local/cpython/Objects/unicodeobject.c:122:5 (python+0x73018f) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #2 unicode_ensure_utf8 /home/mpage/local/cpython/Objects/unicodeobject.c:4225:9 (python+0x74036b) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #3 PyUnicode_AsUTF8AndSize /home/mpage/local/cpython/Objects/unicodeobject.c:4246:9 (python+0x74036b)
    #4 write_unicode_binary /home/mpage/local/cpython/./Modules/_pickle.c:2677:12 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xa219) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #5 save_unicode /home/mpage/local/cpython/./Modules/_pickle.c:2729:13 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xa219)
    #6 save /home/mpage/local/cpython/./Modules/_pickle.c:4392:16 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x940a) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #7 batch_dict_exact /home/mpage/local/cpython/./Modules/_pickle.c:3346:17 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xb682) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #8 save_dict /home/mpage/local/cpython/./Modules/_pickle.c:3408:22 (_pickle.cpython-314td-x86_64-linux-gnu.so+0xb682)
    #9 save /home/mpage/local/cpython/./Modules/_pickle.c:4402:18 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x9624) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #10 dump /home/mpage/local/cpython/./Modules/_pickle.c:4602:9 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x8068) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #11 _pickle_Pickler_dump_impl /home/mpage/local/cpython/./Modules/_pickle.c:4676:9 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x21a74) (BuildId: e2f310e804661a33ae374de41f9979004e07a1e7)
    #12 _pickle_Pickler_dump /home/mpage/local/cpython/./Modules/clinic/_pickle.c.h:73:20 (_pickle.cpython-314td-x86_64-linux-gnu.so+0x21a74)
    #13 cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD /home/mpage/local/cpython/Objects/methodobject.c:468:24 (python+0x6924c6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #14 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:167:11 (python+0x5d48f0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #15 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #16 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:960:35 (python+0x8291e2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #17 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #18 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #19 _PyFunction_Vectorcall /home/mpage/local/cpython/Objects/call.c (python+0x5d6799) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #20 _PyObject_VectorcallDictTstate /home/mpage/local/cpython/Objects/call.c:135:15 (python+0x5d4b88) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #21 _PyObject_Call_Prepend /home/mpage/local/cpython/Objects/call.c:504:24 (python+0x5d6bd2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #22 slot_tp_init /home/mpage/local/cpython/Objects/typeobject.c:10233:15 (python+0x71d085) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #23 type_call /home/mpage/local/cpython/Objects/typeobject.c:2185:19 (python+0x6fd01c) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #24 _PyObject_MakeTpCall /home/mpage/local/cpython/Objects/call.c:242:18 (python+0x5d4fd1) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #25 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:165:16 (python+0x5d4918) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #26 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #27 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:960:35 (python+0x8291e2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #28 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #29 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #30 _PyFunction_Vectorcall /home/mpage/local/cpython/Objects/call.c (python+0x5d6799) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #31 _PyObject_VectorcallDictTstate /home/mpage/local/cpython/Objects/call.c:146:15 (python+0x5d4b64) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #32 _PyObject_Call_Prepend /home/mpage/local/cpython/Objects/call.c:504:24 (python+0x5d6bd2) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #33 slot_tp_init /home/mpage/local/cpython/Objects/typeobject.c:10233:15 (python+0x71d085) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #34 type_call /home/mpage/local/cpython/Objects/typeobject.c:2185:19 (python+0x6fd01c) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #35 _PyObject_MakeTpCall /home/mpage/local/cpython/Objects/call.c:242:18 (python+0x5d4fd1) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #36 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:165:16 (python+0x5d4918) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #37 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #38 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:1993:35 (python+0x8310ad) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #39 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #40 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #41 _PyFunction_Vectorcall /home/mpage/local/cpython/Objects/call.c (python+0x5d6799) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #42 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:167:11 (python+0x5dc820) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #43 method_vectorcall /home/mpage/local/cpython/Objects/classobject.c:71:20 (python+0x5dae9d) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #44 _PyVectorcall_Call /home/mpage/local/cpython/Objects/call.c:273:16 (python+0x5d619d) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #45 _PyObject_Call /home/mpage/local/cpython/Objects/call.c:348:16 (python+0x5d6413) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #46 PyObject_Call /home/mpage/local/cpython/Objects/call.c:373:12 (python+0x5d65c7) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #47 thread_run /home/mpage/local/cpython/./Modules/_threadmodule.c:346:21 (python+0xa28898) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #48 pythread_wrapper /home/mpage/local/cpython/Python/thread_pthread.h:242:5 (python+0x96a4bb) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)

  Thread T1 'Thread-1 (t)' (tid=3454868, running) created by main thread at:
    #0 pthread_create <null> (python+0x47a2df) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #1 do_start_joinable_thread /home/mpage/local/cpython/Python/thread_pthread.h:289:14 (python+0x96920b) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #2 PyThread_start_joinable_thread /home/mpage/local/cpython/Python/thread_pthread.h:313:9 (python+0x96904a) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #3 ThreadHandle_start /home/mpage/local/cpython/./Modules/_threadmodule.c:431:9 (python+0xa283d0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #4 do_start_new_thread /home/mpage/local/cpython/./Modules/_threadmodule.c:1794:9 (python+0xa283d0)
    #5 thread_PyThread_start_joinable_thread /home/mpage/local/cpython/./Modules/_threadmodule.c:1917:14 (python+0xa26a27) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #6 cfunction_call /home/mpage/local/cpython/Objects/methodobject.c:551:18 (python+0x693086) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #7 _PyObject_MakeTpCall /home/mpage/local/cpython/Objects/call.c:242:18 (python+0x5d4fd1) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #8 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:165:16 (python+0x5d4918) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #9 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #10 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:1993:35 (python+0x8310ad) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #11 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #12 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #13 PyEval_EvalCode /home/mpage/local/cpython/Python/ceval.c:658:21 (python+0x8212a6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #14 run_eval_code_obj /home/mpage/local/cpython/Python/pythonrun.c:1338:9 (python+0x94517b) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #15 run_mod /home/mpage/local/cpython/Python/pythonrun.c:1423:19 (python+0x944cfe) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #16 pyrun_file /home/mpage/local/cpython/Python/pythonrun.c:1256:15 (python+0x93f898) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #17 _PyRun_SimpleFileObject /home/mpage/local/cpython/Python/pythonrun.c:491:13 (python+0x93f898)
    #18 _PyRun_AnyFileObject /home/mpage/local/cpython/Python/pythonrun.c:78:15 (python+0x93f059) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #19 pymain_run_file_obj /home/mpage/local/cpython/Modules/main.c:410:15 (python+0x9865f6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #20 pymain_run_file /home/mpage/local/cpython/Modules/main.c:429:15 (python+0x9865f6)
    #21 pymain_run_python /home/mpage/local/cpython/Modules/main.c:697:21 (python+0x985569) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #22 Py_RunMain /home/mpage/local/cpython/Modules/main.c:776:5 (python+0x985569)
    #23 pymain_main /home/mpage/local/cpython/Modules/main.c:806:12 (python+0x985a99) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #24 Py_BytesMain /home/mpage/local/cpython/Modules/main.c:830:12 (python+0x985b19) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #25 main /home/mpage/local/cpython/./Programs/python.c:15:12 (python+0x4f8250) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)

  Thread T18 'Thread-18 (t)' (tid=3454886, running) created by main thread at:
    #0 pthread_create <null> (python+0x47a2df) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #1 do_start_joinable_thread /home/mpage/local/cpython/Python/thread_pthread.h:289:14 (python+0x96920b) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #2 PyThread_start_joinable_thread /home/mpage/local/cpython/Python/thread_pthread.h:313:9 (python+0x96904a) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #3 ThreadHandle_start /home/mpage/local/cpython/./Modules/_threadmodule.c:431:9 (python+0xa283d0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #4 do_start_new_thread /home/mpage/local/cpython/./Modules/_threadmodule.c:1794:9 (python+0xa283d0)
    #5 thread_PyThread_start_joinable_thread /home/mpage/local/cpython/./Modules/_threadmodule.c:1917:14 (python+0xa26a27) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #6 cfunction_call /home/mpage/local/cpython/Objects/methodobject.c:551:18 (python+0x693086) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #7 _PyObject_MakeTpCall /home/mpage/local/cpython/Objects/call.c:242:18 (python+0x5d4fd1) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #8 _PyObject_VectorcallTstate /home/mpage/local/cpython/./Include/internal/pycore_call.h:165:16 (python+0x5d4918) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #9 PyObject_Vectorcall /home/mpage/local/cpython/Objects/call.c:327:12 (python+0x5d62b0) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #10 _PyEval_EvalFrameDefault /home/mpage/local/cpython/Python/generated_cases.c.h:2195:35 (python+0x832b51) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #11 _PyEval_EvalFrame /home/mpage/local/cpython/./Include/internal/pycore_ceval.h:116:16 (python+0x8219b6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #12 _PyEval_Vector /home/mpage/local/cpython/Python/ceval.c:1911:12 (python+0x8219b6)
    #13 PyEval_EvalCode /home/mpage/local/cpython/Python/ceval.c:658:21 (python+0x8212a6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #14 run_eval_code_obj /home/mpage/local/cpython/Python/pythonrun.c:1338:9 (python+0x94517b) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #15 run_mod /home/mpage/local/cpython/Python/pythonrun.c:1423:19 (python+0x944cfe) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #16 pyrun_file /home/mpage/local/cpython/Python/pythonrun.c:1256:15 (python+0x93f898) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #17 _PyRun_SimpleFileObject /home/mpage/local/cpython/Python/pythonrun.c:491:13 (python+0x93f898)
    #18 _PyRun_AnyFileObject /home/mpage/local/cpython/Python/pythonrun.c:78:15 (python+0x93f059) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #19 pymain_run_file_obj /home/mpage/local/cpython/Modules/main.c:410:15 (python+0x9865f6) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #20 pymain_run_file /home/mpage/local/cpython/Modules/main.c:429:15 (python+0x9865f6)
    #21 pymain_run_python /home/mpage/local/cpython/Modules/main.c:697:21 (python+0x985569) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #22 Py_RunMain /home/mpage/local/cpython/Modules/main.c:776:5 (python+0x985569)
    #23 pymain_main /home/mpage/local/cpython/Modules/main.c:806:12 (python+0x985a99) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #24 Py_BytesMain /home/mpage/local/cpython/Modules/main.c:830:12 (python+0x985b19) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)
    #25 main /home/mpage/local/cpython/./Programs/python.c:15:12 (python+0x4f8250) (BuildId: 09e963041ced7dc45ee41bb522bc04b7063f3ff9)

SUMMARY: ThreadSanitizer: data race /home/mpage/local/cpython/./Include/cpython/pyatomic_gcc.h:565:3 in _Py_atomic_store_ptr_release
==================
ThreadSanitizer: reported 1 warnings

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

@mpage
Copy link
Contributor Author

mpage commented Dec 24, 2024

I think the right solution might be to acquire a critical section on op around the body of _PyUnicode_CheckConsistency.

@colesbury
Copy link
Contributor

colesbury commented Dec 24, 2024

I'd lean towards making this an a relaxed atomic load in _PyUnicode_CheckConsistency.

I'd like to avoid critical sections in _PyUnicode_CheckConsistency both because of performance considerations and because it may introduce subtle behavioral changes in code paths that did not lock before. (For example, a critical section may allow for a stop-the-world pause in a place where it was not possible before.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants