diff options
author | Sam Gross <colesbury@gmail.com> | 2024-07-25 08:16:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 08:16:53 (GMT) |
commit | 2f74b709b637cad7a9c18a2d90b0747823f2ff51 (patch) | |
tree | 3ebf71e5f7423d1757793fa17167c0064ba73837 | |
parent | bb108580dec5d8655ccdfb6c8737b5f64e3366d0 (diff) | |
download | cpython-2f74b709b637cad7a9c18a2d90b0747823f2ff51.zip cpython-2f74b709b637cad7a9c18a2d90b0747823f2ff51.tar.gz cpython-2f74b709b637cad7a9c18a2d90b0747823f2ff51.tar.bz2 |
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.
-rw-r--r-- | Lib/test/test_asyncio/utils.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py index dbb8d27..35893ab 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() |