-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(vllm): support IPv6 communicator hosts #6907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5c07d79
eaa4e87
3a9c2f7
4bc391d
e611aef
25a5281
ca910ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,31 @@ | |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _strip_ipv6_brackets(host: str) -> str: | ||
| """Return an IPv6 literal without URL-only brackets.""" | ||
| if host.startswith("[") and host.endswith("]"): | ||
| return host[1:-1] | ||
| return host | ||
|
|
||
|
|
||
| def _resolve_communicator_host(host: str) -> str: | ||
| """Return the TCPStore/NCCL host while preserving legacy hostname resolution.""" | ||
| host = _strip_ipv6_brackets(host) | ||
| for family in (socket.AF_INET, socket.AF_INET6): | ||
| try: | ||
| socket.inet_pton(family, host) | ||
| return host | ||
| except OSError: | ||
| pass | ||
| return socket.gethostbyname(host) | ||
|
|
||
|
|
||
| def _format_http_host(host: str) -> str: | ||
| """Bracket an IPv6 literal when embedding it in an HTTP URL.""" | ||
| host = _strip_ipv6_brackets(host) | ||
| return f"[{host}]" if ":" in host else host | ||
|
|
||
|
|
||
| def pil_to_base64(image): | ||
| buffer = BytesIO() | ||
| image.save(buffer, format="PNG") | ||
|
|
@@ -155,13 +180,13 @@ def __init__( | |
| if base_url is not None: | ||
| # Parse the base_url to extract host and port | ||
| parsed_url = urlparse(base_url) | ||
| self.host = socket.gethostbyname(parsed_url.hostname) | ||
| self.host = _resolve_communicator_host(parsed_url.hostname) | ||
| scheme = parsed_url.scheme or "http" | ||
| self.base_url = f"{scheme}://{parsed_url.netloc}{parsed_url.path}" | ||
| else: | ||
| self.host = host | ||
| self.host = _resolve_communicator_host(host) | ||
| self.server_port = server_port | ||
| self.base_url = f"http://{self.host}:{self.server_port}" | ||
| self.base_url = f"http://{_format_http_host(self.host)}:{self.server_port}" | ||
| self.group_port = group_port | ||
| self.check_server(connection_timeout) # check server and fail after timeout | ||
|
|
||
|
|
@@ -193,7 +218,9 @@ def check_server(self, total_timeout: float = 0.0, retry_interval: float = 2.0): | |
| else: | ||
| if response.status_code == 200: | ||
| if "X-Forwarded-For" in response.headers: | ||
| self.host = response.headers["X-Forwarded-For"] | ||
| self.host = _resolve_communicator_host( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forwarded host resolution can crashMedium Severity A successful health check now passes Additional Locations (1)Reviewed by Cursor Bugbot for commit ca910ca. Configure here. |
||
| response.headers["X-Forwarded-For"] | ||
| ) | ||
| logger.info("Server is up!") | ||
| return None | ||
|
|
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Host path rewrites HTTP to IPv4
Medium Severity
_resolve_communicator_hostnow runssocket.gethostbynameon thehostargument, then_format_http_hostbuildsbase_urlfrom that already-resolved value. A hostname such aslocalhostbecomes an IPv4 HTTP URL and communicator address, so IPv6-only or IPv6-preferred hosts fail even though thebase_urlpath still keeps the original URL separate from the communicator host.Additional Locations (1)
trl/generation/vllm_client.py#L57-L67Reviewed by Cursor Bugbot for commit ca910ca. Configure here.