The test_asyncio.test_sock_lowlevel.py test uses a UDP echo server:
|
def echo_datagrams(sock): |
|
while True: |
|
data, addr = sock.recvfrom(4096) |
|
if data == b'STOP': |
|
sock.close() |
|
break |
|
else: |
|
sock.sendto(data, addr) |
|
|
|
|
|
@contextlib.contextmanager |
|
def run_udp_echo_server(*, host='127.0.0.1', port=0): |
|
addr_info = socket.getaddrinfo(host, port, type=socket.SOCK_DGRAM) |
|
family, type, proto, _, sockaddr = addr_info[0] |
|
sock = socket.socket(family, type, proto) |
|
sock.bind((host, port)) |
|
thread = threading.Thread(target=lambda: echo_datagrams(sock)) |
|
thread.start() |
|
try: |
|
yield sock.getsockname() |
|
finally: |
|
sock.sendto(b'STOP', sock.getsockname()) |
|
thread.join() |
Thread sanitizer complains about the sock.sendto(b'STOP', sock.getsockname()) line in the main thread happening concurrently with the sock.close() in the echo_datagrams thread.
This seems a bit bogus to me: the sendto has to start before the close starts because it triggers the echo_datagrams shutdown, but it's easy enough to avoid the data race. I also think it's better in this case to do a small code change to the test, instead of adding or keeping a global suppression.
Linked PRs
The
test_asyncio.test_sock_lowlevel.pytest uses a UDP echo server:cpython/Lib/test/test_asyncio/utils.py
Lines 288 to 310 in a15fede
Thread sanitizer complains about the
sock.sendto(b'STOP', sock.getsockname())line in the main thread happening concurrently with thesock.close()in theecho_datagramsthread.This seems a bit bogus to me: the
sendtohas to start before theclosestarts because it triggers theecho_datagramsshutdown, but it's easy enough to avoid the data race. I also think it's better in this case to do a small code change to the test, instead of adding or keeping a global suppression.Linked PRs
run_udp_echo_server#122189run_udp_echo_server(GH-122189) #122263