Skip to content

Commit 31312ab

Browse files
committed
[Core] zmq: bind only to 127.0.0.1 for local-only usage
When running with `--tensor-parallel-size` greater than `1`, I noticed that the zmq socket opened for broadcasting to workers was listening on all interfaces. This change makes both the listening-side and (XPUB) and the receiving side (SUB) use `127.0.0.1` instead of `*` when we know the usage is local-only. I also added debug logging to show which port numbers are in use by zmq. By listening on all interfaces, an external party could connect and subscribe to data from the `XPUB` socket if firewall settings allow it. The data received is not particularly useful (it's tensor metadata), but it's still unexpected and undesirable behavior to allow connections from a wider set of potential sources than necessary. It is already possible to control which IP address is used for the remote case by setting the `VLLM_HOST_IP` environment variable. Signed-off-by: Russell Bryant <[email protected]>
1 parent 1b6de83 commit 31312ab

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

vllm/distributed/device_communicators/shm_broadcast.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ def __init__(
196196
# see http://api.zeromq.org/3-3:zmq-setsockopt for more details
197197
self.local_socket.setsockopt(XPUB_VERBOSE, True)
198198
local_subscribe_port = get_open_port()
199-
self.local_socket.bind(f"tcp://*:{local_subscribe_port}")
199+
socket_addr = f"tcp://127.0.0.1:{local_subscribe_port}"
200+
logger.debug("Binding to %s", socket_addr)
201+
self.local_socket.bind(socket_addr)
200202

201203
self.current_idx = 0
202204

@@ -212,7 +214,8 @@ def __init__(
212214
self.remote_socket = context.socket(XPUB)
213215
self.remote_socket.setsockopt(XPUB_VERBOSE, True)
214216
remote_subscribe_port = get_open_port()
215-
self.remote_socket.bind(f"tcp://*:{remote_subscribe_port}")
217+
socket_addr = f"tcp://*:{remote_subscribe_port}"
218+
self.remote_socket.bind(socket_addr)
216219

217220
else:
218221
remote_subscribe_port = None
@@ -255,8 +258,9 @@ def create_from_handle(handle: Handle, rank) -> "MessageQueue":
255258

256259
self.local_socket = context.socket(SUB)
257260
self.local_socket.setsockopt_string(SUBSCRIBE, "")
258-
self.local_socket.connect(
259-
f"tcp://{handle.connect_ip}:{handle.local_subscribe_port}")
261+
socket_addr = f"tcp://127.0.0.1:{handle.local_subscribe_port}"
262+
logger.debug("Connecting to %s", socket_addr)
263+
self.local_socket.connect(socket_addr)
260264

261265
self.remote_socket = None
262266
else:
@@ -270,8 +274,9 @@ def create_from_handle(handle: Handle, rank) -> "MessageQueue":
270274

271275
self.remote_socket = context.socket(SUB)
272276
self.remote_socket.setsockopt_string(SUBSCRIBE, "")
273-
self.remote_socket.connect(
274-
f"tcp://{handle.connect_ip}:{handle.remote_subscribe_port}")
277+
socket_addr = f"tcp://{handle.connect_ip}:{handle.remote_subscribe_port}"
278+
logger.debug("Connecting to %s", socket_addr)
279+
self.remote_socket.connect(socket_addr)
275280

276281
return self
277282

0 commit comments

Comments
 (0)