sgl-project/sglang · critical · RuntimeError

Server process exited with code {return_code}

Error message

Server process exited with code {return_code}

What it means

wait_for_http_ready's _raise_if_process_exited polled the server process and found it already terminated with a known exit code, so readiness waiting aborts instead of hanging on a dead server.

Source

Thrown at python/sglang/utils.py:542

    Terminate the process and automatically release the reserved port.
    """
    from sglang.srt.utils import kill_process_tree

    kill_process_tree(process.pid)

    lock_socket = process_socket_map.pop(process, None)
    if lock_socket is not None:
        release_port(lock_socket)


def _raise_if_process_exited(process: Optional[Any]) -> None:
    if process is None:
        return

    if hasattr(process, "poll"):
        return_code = process.poll()
        if return_code is not None:
            raise RuntimeError(f"Server process exited with code {return_code}")
        return

    if hasattr(process, "is_alive") and not process.is_alive():
        return_code = getattr(process, "exitcode", None)
        if return_code is None:
            raise RuntimeError("Server process exited")
        raise RuntimeError(f"Server process exited with code {return_code}")


def _is_wait_timeout(start_time: float, timeout: Optional[int]) -> bool:
    if timeout is None:
        return False
    return time.perf_counter() - start_time > timeout


def wait_for_http_ready(
    url: str,
    timeout: Optional[int] = None,

View on GitHub (pinned to 0132848349)

Solutions

  1. Reproduce the server launch manually and read its stdout/stderr for the root cause
  2. Fix the underlying startup failure (model path, GPU memory, flags)
  3. Retain and print the process output in the test harness for diagnosis
Defensive patterns

Strategy: try-catch

Try / catch

try:
    wait_for_http_ready(server_process, url)
except RuntimeError as e:
    if 'exited with code' in str(e):
        print(server_process.stdout.read())  # surface root cause

Prevention

When it happens

Trigger: Server subprocess crashes during startup (bad args, OOM, CUDA error, import failure) while the test harness polls /health.

Common situations: Benchmarks/tests calling launch_server_cmd then wait_for_http_ready; server exits due to invalid model path or GPU error.

Related errors


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