sgl-project/sglang · error · RuntimeError

Lost connection to server after {consecutive_errors} consecu

Error message

Lost connection to server after {consecutive_errors} consecutive errors. Server may be unavailable: {str(e)}

What it means

RuntimeError raised in generate_video when the status-polling GET keeps failing with requests ConnectionError for max_consecutive_errors attempts in a row. It indicates the server became unreachable mid-job, not that the job itself failed.

Source

Thrown at python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py:340

                    # Reset error counter on successful request
                    consecutive_errors = 0

                    if status.get("status") == "completed":
                        return status
                    elif status.get("status") == "failed":
                        error = status.get("error", {})
                        error_msg = (
                            error.get("message", "Unknown error")
                            if error
                            else "Unknown error"
                        )
                        raise RuntimeError(f"Video generation failed: {error_msg}")
                except requests.exceptions.ConnectionError as e:
                    # Connection errors - likely server is down
                    consecutive_errors += 1
                    if consecutive_errors >= max_consecutive_errors:
                        raise RuntimeError(
                            f"Lost connection to server after {consecutive_errors} consecutive errors. "
                            f"Server may be unavailable: {str(e)}"
                        )
                except requests.exceptions.RequestException as e:
                    # Other network errors - continue polling but track errors
                    consecutive_errors += 1
                    if consecutive_errors >= max_consecutive_errors:
                        raise RuntimeError(
                            f"Network error after {consecutive_errors} consecutive failures: {str(e)}"
                        )

                time.sleep(poll_interval)

            raise TimeoutError(
                f"Video generation timed out after {max_wait_time} seconds"
            )
        except requests.exceptions.RequestException as e:
            raise RuntimeError(f"Failed to generate video: {str(e)}")

View on GitHub (pinned to 0132848349)

Solutions

  1. Check whether the server process is still alive (it likely crashed — inspect its logs/OOM killer messages).
  2. Restart the server and resubmit the job with smaller size/seconds to avoid the crash cause.
  3. If network flakiness rather than a crash, raise max_consecutive_errors when calling generate_video.
  4. Add retry-from-job-id logic if the server persists jobs across restarts.

Example fix

// before
result = api.generate_video(prompt=p)  # Lost connection to server ...
// after
# tolerate transient drops
result = api.generate_video(prompt=p, max_consecutive_errors=20, poll_interval=5)
Defensive patterns

Strategy: retry

Validate before calling

import requests
requests.get(base_url, timeout=5).raise_for_status()  # before polling jobs

Try / catch

try:
    result = api.generate_video(prompt=p)
except RuntimeError as e:
    if 'Lost connection' in str(e):
        restart_server_and_resubmit()  # job likely killed the server
    else:
        raise

Prevention

When it happens

Trigger: The SGLang Diffusion server crashes, is killed, or the network drops while a video job is being polled; every poll during the loop hits ConnectionError until the consecutive-error budget is exhausted.

Common situations: Server OOM-killed by a long video job; server restarted during generation; Docker/network interruption between client and server.

Related errors


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