8000 [3.13] gh-122187: Avoid TSan reported race in `run_udp_echo_server` (… · python/cpython@977c799 · GitHub
[go: up one dir, main page]

Skip to content

Commit 977c799

Browse files
[3.13] gh-122187: Avoid TSan reported race in run_udp_echo_server (GH-122189) (#122263)
gh-122187: Avoid TSan reported race in `run_udp_echo_server` (GH-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. (cherry picked from commit 2f74b70) Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 6933c4a commit 977c799

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