Skip to content

Commit bf4adc4

Browse files
committed
fix get_ip/get_open_port failure in pure ipv6 environment
1 parent 264017a commit bf4adc4

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

vllm/utils.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +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]
178-
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]
179192

180193
def set_cuda_visible_devices(device_ids: List[int]) -> None:
181194
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, device_ids))

0 commit comments

Comments
 (0)