https://github.com/python/cpython/commit/977c7992860a58f7a48bcdac53a99e67e5bb9b9c
commit: 977c7992860a58f7a48bcdac53a99e67e5bb9b9c
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2024-07-25T08:42:38Z
summary:

[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 2f74b709b637cad7a9c18a2d90b0747823f2ff51)

Co-authored-by: Sam Gross <[email protected]>

files:
M Lib/test/test_asyncio/utils.py

diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index 44943e1fa7bc4e..ce2408fc1aabfb 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -301,12 +301,17 @@ def run_udp_echo_server(*, host='127.0.0.1', port=0):
     family, type, proto, _, sockaddr = addr_info[0]
     sock = socket.socket(family, type, proto)
     sock.bind((host, port))
+    sockname = sock.getsockname()
     thread = threading.Thread(target=lambda: echo_datagrams(sock))
     thread.start()
     try:
-        yield sock.getsockname()
+        yield sockname
     finally:
-        sock.sendto(b'STOP', sock.getsockname())
+        # gh-122187: use a separate socket to send the stop message to avoid
+        # TSan reported race on the same socket.
+        sock2 = socket.socket(family, type, proto)
+        sock2.sendto(b'STOP', sockname)
+        sock2.close()
         thread.join()
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to