Skip to content

Commit 3dbab3f

Browse files
authored
fix(sglang): fix IPv6 support for ZMQ endpoint (#4403)
Signed-off-by: Dmitrii Gabor <[email protected]>
1 parent 21f6d1e commit 3dbab3f

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

components/src/dynamo/sglang/publisher.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import zmq
1111
import zmq.asyncio
1212
from prometheus_client import CollectorRegistry, multiprocess
13-
from sglang.srt.utils import get_local_ip_auto, get_zmq_socket
13+
from sglang.srt.utils import get_local_ip_auto, get_zmq_socket, maybe_wrap_ipv6_address
1414

1515
from dynamo.common.utils.prometheus import register_engine_metrics_callback
1616
from dynamo.llm import (
@@ -26,6 +26,30 @@
2626
from dynamo.sglang.args import Config
2727

2828

29+
def format_zmq_endpoint(endpoint_template: str, ip_address: str) -> str:
30+
"""Format ZMQ endpoint by replacing wildcard with IP address.
31+
32+
Properly handles IPv6 addresses by wrapping them in square brackets.
33+
Uses SGLang's maybe_wrap_ipv6_address for consistent formatting.
34+
35+
Args:
36+
endpoint_template: ZMQ endpoint template with wildcard (e.g., "tcp://*:5557")
37+
ip_address: IP address to use (can be IPv4 or IPv6)
38+
39+
Returns:
40+
Formatted ZMQ endpoint string
41+
42+
Example:
43+
>>> format_zmq_endpoint("tcp://*:5557", "192.168.1.1")
44+
'tcp://192.168.1.1:5557'
45+
>>> format_zmq_endpoint("tcp://*:5557", "2a02:6b8:c46:2b4:0:74c1:75b0:0")
46+
'tcp://[2a02:6b8:c46:2b4:0:74c1:75b0:0]:5557'
47+
"""
48+
# Use SGLang's utility to wrap IPv6 addresses in brackets
49+
formatted_ip = maybe_wrap_ipv6_address(ip_address)
50+
return endpoint_template.replace("*", formatted_ip)
51+
52+
2953
class DynamoSglangPublisher:
3054
"""
3155
Handles SGLang kv events and metrics reception and publishing.
@@ -121,7 +145,7 @@ def init_kv_event_publish(self) -> Optional[ZmqKvEventPublisher]:
121145
if self.server_args.kv_events_config:
122146
kv_events = json.loads(self.server_args.kv_events_config)
123147
ep = kv_events.get("endpoint")
124-
zmq_ep = ep.replace("*", get_local_ip_auto()) if ep else None
148+
zmq_ep = format_zmq_endpoint(ep, get_local_ip_auto()) if ep else None
125149

126150
zmq_config = ZmqKvEventPublisherConfig(
127151
worker_id=self.generate_endpoint.connection_id(),

0 commit comments

Comments
 (0)