{"record":{"id":"fa00eb4d5d19b83a","repo":"sgl-project/sglang","slug":"lost-connection-to-server-after-consecutive-error","errorCode":null,"errorMessage":"Lost connection to server after {consecutive_errors} consecutive errors. Server may be unavailable: {str(e)}","messagePattern":"Lost connection to server after (.+?) consecutive errors\\. Server may be unavailable: (.+?)","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py","lineNumber":340,"sourceCode":"\n                    # Reset error counter on successful request\n                    consecutive_errors = 0\n\n                    if status.get(\"status\") == \"completed\":\n                        return status\n                    elif status.get(\"status\") == \"failed\":\n                        error = status.get(\"error\", {})\n                        error_msg = (\n                            error.get(\"message\", \"Unknown error\")\n                            if error\n                            else \"Unknown error\"\n                        )\n                        raise RuntimeError(f\"Video generation failed: {error_msg}\")\n                except requests.exceptions.ConnectionError as e:\n                    # Connection errors - likely server is down\n                    consecutive_errors += 1\n                    if consecutive_errors >= max_consecutive_errors:\n                        raise RuntimeError(\n                            f\"Lost connection to server after {consecutive_errors} consecutive errors. \"\n                            f\"Server may be unavailable: {str(e)}\"\n                        )\n                except requests.exceptions.RequestException as e:\n                    # Other network errors - continue polling but track errors\n                    consecutive_errors += 1\n                    if consecutive_errors >= max_consecutive_errors:\n                        raise RuntimeError(\n                            f\"Network error after {consecutive_errors} consecutive failures: {str(e)}\"\n                        )\n\n                time.sleep(poll_interval)\n\n            raise TimeoutError(\n                f\"Video generation timed out after {max_wait_time} seconds\"\n            )\n        except requests.exceptions.RequestException as e:\n            raise RuntimeError(f\"Failed to generate video: {str(e)}\")","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py#L322-L358","documentation":"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.","triggerScenarios":"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.","commonSituations":"Server OOM-killed by a long video job; server restarted during generation; Docker/network interruption between client and server.","solutions":["Check whether the server process is still alive (it likely crashed — inspect its logs/OOM killer messages).","Restart the server and resubmit the job with smaller size/seconds to avoid the crash cause.","If network flakiness rather than a crash, raise max_consecutive_errors when calling generate_video.","Add retry-from-job-id logic if the server persists jobs across restarts."],"exampleFix":"// before\nresult = api.generate_video(prompt=p)  # Lost connection to server ...\n// after\n# tolerate transient drops\nresult = api.generate_video(prompt=p, max_consecutive_errors=20, poll_interval=5)","handlingStrategy":"retry","validationCode":"import requests\nrequests.get(base_url, timeout=5).raise_for_status()  # before polling jobs","typeGuard":null,"tryCatchPattern":"try:\n    result = api.generate_video(prompt=p)\nexcept RuntimeError as e:\n    if 'Lost connection' in str(e):\n        restart_server_and_resubmit()  # job likely killed the server\n    else:\n        raise","preventionTips":["Monitor server memory during long video jobs.","Pass a larger max_consecutive_errors on flaky networks.","Keep the job id so it can be re-polled after recovery."],"tags":["network","connection-lost","video-generation","polling","sgldiffusion"],"backgroundTag":"connection-lost-during-polling","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}