Open pitrou opened 8 months ago
@colesbury @gpshead @mpage @erlend-aasland
It happens from https://github.com/python/cpython/actions/runs/11160718143/job/31021782828?pr=124914 too Maybe worth to fix it.
==================
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)
Bug report
Bug description:
The
sock_fd
member inPySocketSockObject
can be mutated while the socket is being used, for example when callingsocket.close
orsocket.detach
. However, some other threads can access that member without holding the GIL, and without using atomic instructions. This can trip up Thread Sanitizer intest_asyncio
, for example:CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux