Skip to content

Commit 2410e32

Browse files
authored
fix get_ip error in pure ipv6 environment (#2931)
1 parent 48a8f4a commit 2410e32

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

vllm/utils.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,33 @@ def _async_wrapper(*args, **kwargs) -> asyncio.Future:
162162

163163

164164
def get_ip() -> str:
165+
# try ipv4
165166
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
166-
s.connect(("8.8.8.8", 80)) # Doesn't need to be reachable
167-
return s.getsockname()[0]
167+
try:
168+
s.connect(("dns.google", 80)) # Doesn't need to be reachable
169+
return s.getsockname()[0]
170+
except OSError:
171+
# try ipv6
172+
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
173+
s.connect(("dns.google", 80))
174+
return s.getsockname()[0]
168175

169176

170177
def get_distributed_init_method(ip: str, port: int) -> str:
171178
return f"tcp://{ip}:{port}"
172179

173180

174181
def get_open_port() -> int:
175-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
176-
s.bind(("", 0))
177-
return s.getsockname()[1]
182+
# try ipv4
183+
try:
184+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
185+
s.bind(("", 0))
186+
return s.getsockname()[1]
187+
except OSError:
188+
# try ipv6
189+
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
190+
s.bind(("", 0))
191+
return s.getsockname()[1]
178192

179193

180194
def set_cuda_visible_devices(device_ids: List[int]) -> None:

0 commit comments

Comments
 (0)