sgl-project/sglang · error · ValueError

Unsupported socket type: {socket_type}

Error message

Unsupported socket type: {socket_type}

What it means

Thrown by get_zmq_socket when the requested zmq socket type is not one of the handled kinds (PUSH/PUB via set_send_opt, PULL/SUB, or DEALER/REQ/REP/ROUTER which set both). Any other socket type constant is rejected.

Source

Thrown at python/sglang/multimodal_gen/runtime/utils/common.py:258

        socket.setsockopt(zmq.IPV6, 1)

    def set_send_opt():
        socket.setsockopt(zmq.SNDHWM, 0)
        socket.setsockopt(zmq.SNDBUF, buf_size)

    def set_recv_opt():
        socket.setsockopt(zmq.RCVHWM, 0)
        socket.setsockopt(zmq.RCVBUF, buf_size)

    if socket_type == zmq.PUSH:
        set_send_opt()
    elif socket_type == zmq.PULL:
        set_recv_opt()
    elif socket_type in [zmq.DEALER, zmq.REQ, zmq.REP, zmq.ROUTER]:
        set_send_opt()
        set_recv_opt()
    else:
        raise ValueError(f"Unsupported socket type: {socket_type}")

    if bind:
        # Parse port from endpoint for retry logic
        import re

        port_match = re.search(r":(\d+)$", endpoint)

        if port_match and max_bind_retries > 1:
            import time as _time

            original_port = int(port_match.group(1))
            last_exception = None

            for attempt in range(max_bind_retries):
                try:
                    current_endpoint = endpoint
                    if attempt > 0 and not same_port:
                        # Try next port (increment by 42 to match settle_port logic)

View on GitHub (pinned to 0132848349)

Solutions

  1. Use one of the supported types: PUSH, PUB, PULL, SUB, DEALER, REQ, REP, ROUTER
  2. If you need another type (e.g. PAIR), extend get_zmq_socket in common.py with an appropriate branch (set_send_opt/set_recv_opt or neither)
  3. Check for a typo — passing an uninitialized/incorrect zmq constant can land in the else branch

Example fix

# before
sock = get_zmq_socket(ctx, zmq.PAIR, "tcp://127.0.0.1:5555", bind=True)
# after
sock = get_zmq_socket(ctx, zmq.DEALER, "tcp://127.0.0.1:5555", bind=True)
Defensive patterns

Strategy: type-guard

Validate before calling

import zmq
SUPPORTED = {zmq.PUSH, zmq.PUB, zmq.PULL, zmq.SUB, zmq.DEALER, zmq.REQ, zmq.REP, zmq.ROUTER}
assert socket_type in SUPPORTED, f"unsupported zmq type {socket_type}"

Type guard

def is_supported_zmq_type(t: int) -> bool:
    import zmq
    return t in (zmq.PUSH, zmq.PUB, zmq.PULL, zmq.SUB, zmq.DEALER, zmq.REQ, zmq.REP, zmq.ROUTER)

Try / catch

try:
    sock = get_zmq_socket(ctx, stype, ep, bind=True)
except ValueError as e:
    if "Unsupported socket type" in str(e):
        stype = zmq.DEALER  # fallback to a supported pattern
        sock = get_zmq_socket(ctx, stype, ep, bind=True)
    else:
        raise

Prevention

When it happens

Trigger: Calling get_zmq_socket with e.g. zmq.PAIR, zmq.XPUB, zmq.XSUB, or zmq.STREAM — types outside the supported set.

Common situations: Adding a new ZMQ pattern (PAIR for 1:1 channels, XPUB/XSUB for fan-out) to the runtime without extending get_zmq_socket's branch list.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/c3264b2df5d09f38. Report an issue: GitHub.