From 6b737fd4c675c65d6544bb7013d017688bb6f7c8 Mon Sep 17 00:00:00 2001 From: metamergebot Date: Tue, 6 Oct 2026 15:50:59 -0700 Subject: [PATCH] Bind the MessageQueue remote socket atomically (#42695) Co-authored-by: merrymercy Co-authored-by: charlotte12l --- .../distributed/device_communicators/shm_broadcast.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/distributed/device_communicators/shm_broadcast.py b/python/sglang/srt/distributed/device_communicators/shm_broadcast.py index 38f2497905..c797cff7e1 100644 --- a/python/sglang/srt/distributed/device_communicators/shm_broadcast.py +++ b/python/sglang/srt/distributed/device_communicators/shm_broadcast.py @@ -239,9 +239,12 @@ class MessageQueue: na = NetworkAddress(connect_ip, remote_subscribe_port) if na.is_ipv6: self.remote_socket.setsockopt(IPV6, 1) - address = na.to_tcp() - logger.debug(f"class MessageQueue: Binding remote socket to {address=}") - self.remote_socket.bind(address) + # get_open_port() only probes; bind atomically in a window from that port. + remote_subscribe_port = self.remote_socket.bind_to_random_port( + na.to_tcp().rsplit(":", 1)[0], # address without the port + min_port=remote_subscribe_port, + max_port=remote_subscribe_port + 32, + ) else: remote_subscribe_port = None