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

TSan: data race accessing socket fd #116912

Open
pitrou opened this issue Mar 16, 2024 · 3 comments
Open

TSan: data race accessing socket fd #116912

pitrou opened this issue Mar 16, 2024 · 3 comments
Labels
extension-modules C modules in the Modules dir tests Tests in the Lib/test dir topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Mar 16, 2024

Bug report

Bug description:

The sock_fd member in PySocketSockObject can be mutated while the socket is being used, for example when calling socket.close or socket.detach. However, some other threads can access that member without holding the GIL, and without using atomic instructions. This can trip up Thread Sanitizer in test_asyncio, for example:

0:00:31 load avg: 3.29 [15/52/1] test_asyncio.test_sock_lowlevel worker non-zero exit code (Exit code 66)
==================
WARNING: ThreadSanitizer: data race (pid=7227)
  Write of size 4 at 0x7fd903611570 by thread T19:
    #0 sock_close /home/runner/work/cpython/cpython/./Modules/socketmodule.c:3339:20 (_socket.cpython-313d-x86_64-linux-gnu.so+0xdbde) (BuildId: 7a12da96172d453cd023792c027755908db49f4e)
[...]

  Previous read of size 4 at 0x7fd903611570 by main thread:
    #0 sock_sendto_impl /home/runner/work/cpython/cpython/./Modules/socketmodule.c:4474:29 (_socket.cpython-313d-x86_64-linux-gnu.so+0x131e5) (BuildId: 7a12da96172d453cd023792c027755908db49f4e)
    #1 sock_call_ex /home/runner/work/cpython/cpython/./Modules/socketmodule.c:968:19 (_socket.cpython-313d-x86_64-linux-gnu.so+0x10fa1) (BuildId: 7a12da96172d453cd023792c027755908db49f4e)
    #2 sock_call /home/runner/work/cpython/cpython/./Modules/socketmodule.c:1020:12 (_socket.cpython-313d-x86_64-linux-gnu.so+0xf1a1) (BuildId: 7a12da96172d453cd023792c027755908db49f4e)
    #3 sock_sendto /home/runner/work/cpython/cpython/./Modules/socketmodule.c:4532:9 (_socket.cpython-313d-x86_64-linux-gnu.so+0xf1a1)
[...]

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

@pitrou pitrou added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Mar 16, 2024
@pitrou pitrou changed the title TSan: data race access socket fd TSan: data race accessing socket fd Mar 16, 2024
@pitrou
Copy link
Member Author

pitrou commented Mar 16, 2024

@pitrou pitrou added the extension-modules C modules in the Modules dir label Mar 16, 2024
@python python deleted a comment from Davidzcdn Jul 10, 2024
@python python deleted a comment from Davidzcdn Jul 10, 2024
@corona10
Copy link
Member

corona10 commented Oct 3, 2024

@corona10
Copy link
Member

corona10 commented Oct 3, 2024

 ==================
WARNING: ThreadSanitizer: data race (pid=11811)
  Write of size 4 at 0x7f788e470220 by main thread:
    #0 _socket_socket_close_impl /home/runner/work/cpython/cpython/./Modules/socketmodule.c:3369:20 (_socket.cpython-314td-x86_64-linux-gnu.so+0xe6fa) (BuildId: fd621939d2f906d64ec9d9113f22b21082c40173)
    #1 _socket_socket_close /home/runner/work/cpython/cpython/./Modules/clinic/socketmodule.c.h:32:20 (_socket.cpython-314td-x86_64-linux-gnu.so+0xe6fa)
    #2 method_vectorcall_NOARGS /home/runner/work/cpython/cpython/Objects/descrobject.c:447:24 (python+0x27d040) (BuildId: f4b70dfbd84ba1a7db1e594342dc691a3ebbd7b7)
    #3 _PyObject_VectorcallTstate /home/runner/work/cpython/cpython/./Include/internal/pycore_call.h:167:11 (python+0x261c31) (BuildId: f4b70dfbd84ba1a7db1e594342dc691a3ebbd7b7)
    #4 PyObject_Vectorcall /home/runner/work/cpython/cpython/Objects/call.c:327:12 (python+0x263730) (BuildId: f4b70dfbd84ba1a7db1e594342dc691a3ebbd7b7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir tests Tests in the Lib/test dir topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants