8000 gh-122187: Avoid TSan reported race in `run_udp_echo_server` (#122189) · python/cpython@2f74b70 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f74b70

Browse files
authored
gh-122187: Avoid TSan reported race in run_udp_echo_server (#122189)
TSan doesn't fully recognize the synchronization via I/O, so ensure that socket name is retrieved earlier and use a different socket for sending the "STOP" message.
1 parent bb10858 commit 2f74b70

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/test/test_asyncio/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,17 @@ def run_udp_echo_server(*, host='127.0.0.1', port=0):
301301
family, type, proto, _, sockaddr = addr_info[0]
302302
sock = socket.socket(family, type, proto)
303303
sock.bind((host, port))
304+
sockname = sock.getsockname()
304305
thread = threading.Thread(target=lambda: echo_datagrams(sock))
305306
thread.start()
306307
try:
307-
yield sock.getsockname()
308+
yield sockname
308309
finally:
309-
sock.sendto(b'STOP', sock.getsockname())
310+
# gh-122187: use a separate socket to send the stop message to avoid
311+
# TSan reported race on the same socket.
312+
sock2 = socket.socket(family, type, proto)
313+
sock2.sendto(b'STOP', sockname)
314+
sock2.close()
310315
thread.join()
311316

312317

0 commit comments

Comments
 (0)
0