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

gh-117657: Move static variables in fileutils.c to thread state #120559

Closed

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jun 15, 2024

Example race reported by TSAN:

WARNING: ThreadSanitizer: data race (pid=18775)
  Read of size 4 at 0x555555e963f4 by thread T2:
    #0 set_inheritable /home/ken/Documents/GitHub/cpython/Python/fileutils.c:1505:9 (python+0x5f2ff3) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #1 _Py_set_inheritable /home/ken/Documents/GitHub/cpython/Python/fileutils.c:1605:12 (python+0x5f2efe) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #2 _io_FileIO___init___impl /home/ken/Documents/GitHub/cpython/./Modules/_io/fileio.c:447:13 (python+0x643251) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #3 _io_FileIO___init__ /home/ken/Documents/GitHub/cpython/./Modules/_io/clinic/fileio.c.h:134:20 (python+0x643251)
    #4 type_call /home/ken/Documents/GitHub/cpython/Objects/typeobject.c:2143:19 (python+0x386af6) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #5 _PyObject_MakeTpCall /home/ken/Documents/GitHub/cpython/Objects/call.c:242:18 (python+0x259183) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #6 _PyObject_VectorcallTstate /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_call.h:166:16 (python+0x25b406) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #7 _PyObject_CallFunctionVa /home/ken/Documents/GitHub/cpython/Objects/call.c (python+0x25b406)
    #8 PyObject_CallFunction /home/ken/Documents/GitHub/cpython/Objects/call.c:574:14 (python+0x25b0d3) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #9 _io_open_impl /home/ken/Documents/GitHub/cpython/./Modules/_io/_iomodule.c:331:15 (python+0x63ca77) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #10 _io_open /home/ken/Documents/GitHub/cpython/./Modules/_io/clinic/_iomodule.c.h:293:20 (python+0x63ca77)
    #11 cfunction_vectorcall_FASTCALL_KEYWORDS /home/ken/Documents/GitHub/cpython/Objects/methodobject.c:441:24 (python+0x318c4c) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #12 _PyObject_VectorcallTstate /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_call.h:168:11 (python+0x2589c1) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #13 PyObject_Vectorcall /home/ken/Documents/GitHub/cpython/Objects/call.c:327:12 (python+0x25a590) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #14 _PyEval_EvalFrameDefault /home/ken/Documents/GitHub/cpython/Python/generated_cases.c.h:1505:19 (python+0x4a5973) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #15 _PyEval_EvalFrame /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_ceval.h:119:16 (python+0x49b343) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #16 _PyEval_Vector /home/ken/Documents/GitHub/cpython/Python/ceval.c:1819:12 (python+0x49b343)
    #17 _PyFunction_Vectorcall /home/ken/Documents/GitHub/cpython/Objects/call.c (python+0x25aabe) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #18 _PyObject_VectorcallTstate /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_call.h:168:11 (python+0x260c31) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #19 method_vectorcall /home/ken/Documents/GitHub/cpython/Objects/classobject.c:70:20 (python+0x25ef55) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #20 _PyVectorcall_Call /home/ken/Documents/GitHub/cpython/Objects/call.c:273:16 (python+0x25a45f) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #21 _PyObject_Call /home/ken/Documents/GitHub/cpython/Objects/call.c:348:16 (python+0x25a6f7) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #22 PyObject_Call /home/ken/Documents/GitHub/cpython/Objects/call.c:373:12 (python+0x25a8e7) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #23 thread_run /home/ken/Documents/GitHub/cpython/./Modules/_threadmodule.c:337:21 (python+0x6a2168) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #24 pythread_wrapper /home/ken/Documents/GitHub/cpython/Python/thread_pthread.h:243:5 (python+0x5dd89b) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)

  Previous write of size 4 at 0x555555e963f4 by thread T1:
    #0 set_inheritable /home/ken/Documents/GitHub/cpython/Python/fileutils.c:1515:25 (python+0x5f30f9) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #1 _Py_set_inheritable /home/ken/Documents/GitHub/cpython/Python/fileutils.c:1605:12 (python+0x5f2efe) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #2 _io_FileIO___init___impl /home/ken/Documents/GitHub/cpython/./Modules/_io/fileio.c:447:13 (python+0x643251) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #3 _io_FileIO___init__ /home/ken/Documents/GitHub/cpython/./Modules/_io/clinic/fileio.c.h:134:20 (python+0x643251)
    #4 type_call /home/ken/Documents/GitHub/cpython/Objects/typeobject.c:2143:19 (python+0x386af6) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #5 _PyObject_MakeTpCall /home/ken/Documents/GitHub/cpython/Objects/call.c:242:18 (python+0x259183) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #6 _PyObject_VectorcallTstate /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_call.h:166:16 (python+0x25b406) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #7 _PyObject_CallFunctionVa /home/ken/Documents/GitHub/cpython/Objects/call.c (python+0x25b406)
    #8 PyObject_CallFunction /home/ken/Documents/GitHub/cpython/Objects/call.c:574:14 (python+0x25b0d3) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #9 _io_open_impl /home/ken/Documents/GitHub/cpython/./Modules/_io/_iomodule.c:331:15 (python+0x63ca77) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #10 _io_open /home/ken/Documents/GitHub/cpython/./Modules/_io/clinic/_iomodule.c.h:293:20 (python+0x63ca77)
    #11 cfunction_vectorcall_FASTCALL_KEYWORDS /home/ken/Documents/GitHub/cpython/Objects/methodobject.c:441:24 (python+0x318c4c) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #12 _PyObject_VectorcallTstate /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_call.h:168:11 (python+0x2589c1) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #13 PyObject_Vectorcall /home/ken/Documents/GitHub/cpython/Objects/call.c:327:12 (python+0x25a590) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #14 _PyEval_EvalFrameDefault /home/ken/Documents/GitHub/cpython/Python/generated_cases.c.h:1505:19 (python+0x4a5973) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #15 _PyEval_EvalFrame /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_ceval.h:119:16 (python+0x49b343) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #16 _PyEval_Vector /home/ken/Documents/GitHub/cpython/Python/ceval.c:1819:12 (python+0x49b343)
    #17 _PyFunction_Vectorcall /home/ken/Documents/GitHub/cpython/Objects/call.c (python+0x25aabe) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #18 _PyObject_VectorcallTstate /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_call.h:168:11 (python+0x260c31) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #19 method_vectorcall /home/ken/Documents/GitHub/cpython/Objects/classobject.c:70:20 (python+0x25ef55) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #20 _PyVectorcall_Call /home/ken/Documents/GitHub/cpython/Objects/call.c:273:16 (python+0x25a45f) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #21 _PyObject_Call /home/ken/Documents/GitHub/cpython/Objects/call.c:348:16 (python+0x25a6f7) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #22 PyObject_Call /home/ken/Documents/GitHub/cpython/Objects/call.c:373:12 (python+0x25a8e7) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #23 thread_run /home/ken/Documents/GitHub/cpython/./Modules/_threadmodule.c:337:21 (python+0x6a2168) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)
    #24 pythread_wrapper /home/ken/Documents/GitHub/cpython/Python/thread_pthread.h:243:5 (python+0x5dd89b) (BuildId: aebd4996d08922f5e3af359bb646def4e05d4a16)

  Location is global 'set_inheritable.ioctl_works' of size 4 at 0x555555e963f4 (python+0x9423f4)

@ericsnowcurrently
Copy link
Member

Out of curiosity, why did you close this?

@Fidget-Spinner
Copy link
Member Author

I couldnt get it to not crash and I didnt know why :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants