[Bugfix] Fix ZMQ port TOCTOU race in shm_broadcast MessageQueue (#50960)

Signed-off-by: RTCartist <wangshengb@buaa.edu.cn>
Signed-off-by: aoshen02 <aoshen02@users.noreply.github.com>
Co-authored-by: RTCartist <wangshengb@buaa.edu.cn>
Co-authored-by: aoshen02 <aoshen02@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
aoshen02
2026-08-07 18:19:02 -07:00
committed by GitHub
co-authored by RTCartist aoshen02 Claude Fable 5
parent 7f58e8294a
commit f7ef489e93
2 changed files with 68 additions and 4 deletions
@@ -36,7 +36,6 @@ from vllm.logger import init_logger
from vllm.platforms import current_platform
from vllm.utils.network_utils import (
get_ip,
get_open_port,
get_open_zmq_inproc_path,
get_open_zmq_ipc_path,
is_valid_ipv6_address,
@@ -525,13 +524,13 @@ class MessageQueue:
connect_ip = get_ip()
self.remote_socket = context.socket(XPUB)
self.remote_socket.setsockopt(XPUB_VERBOSE, True)
remote_subscribe_port = get_open_port()
if is_valid_ipv6_address(connect_ip):
self.remote_socket.setsockopt(IPV6, 1)
remote_addr_ipv6 = True
connect_ip = f"[{connect_ip}]"
socket_addr = f"tcp://{connect_ip}:{remote_subscribe_port}"
self.remote_socket.bind(socket_addr)
self.remote_socket.bind(f"tcp://{connect_ip}:0")
last_endpoint = self.remote_socket.getsockopt(zmq.LAST_ENDPOINT)
remote_subscribe_port = last_endpoint.decode().rsplit(":", 1)[1]
remote_subscribe_addr = f"tcp://{connect_ip}:{remote_subscribe_port}"
else:
remote_subscribe_addr = None