unslothai/unsloth · error · RuntimeError
sd-server connection lost during img_gen submit
Error message
sd-server connection lost during img_gen submit
What it means
The HTTP POST that submits an img_gen job failed at the transport layer (connection reset/refused, or httpx timeout) and the server is no longer alive, so the wrapper classifies it as the server having died during submit rather than transient network trouble. The full _died_message form appends the underlying transport exception and log tail. At submit time the connection was just verified alive, so a transport error here strongly implies a crash.
Source
Thrown at studio/backend/core/inference/sd_cpp_server.py:464
Raises ``RuntimeError`` on submit/poll failures (including the server dying), with
the log tail attached.
"""
# Already stopped with the cancel event set: report cancellation (route 409), not a generic "server died" 500.
if self._stopped or not self.is_alive():
if cancel_event is not None and cancel_event.is_set():
raise SdCppCancelled("sd-server generation was cancelled.")
raise RuntimeError("sd-server is not running.")
self._step_listener = on_step
job_id: Optional[str] = None
try:
# Submit -> 202 Accepted + job id.
try:
resp = self._client.post(
f"{self.base_url}{_IMG_GEN_PATH}", json = payload, timeout = submit_timeout
)
except (*_TRANSPORT_ERRORS, httpx.TimeoutException) as exc:
raise RuntimeError(self._died_message("img_gen submit", exc)) from exc
if resp.status_code == 429:
raise RuntimeError("sd-server job queue is full (HTTP 429).")
if resp.status_code not in (200, 202):
raise RuntimeError(
f"sd-server img_gen submit -> {resp.status_code}: {resp.text[:500]}"
)
try:
job = resp.json()
except ValueError as exc:
raise RuntimeError(
f"sd-server img_gen returned a non-JSON submit response: {exc}"
) from exc
if not isinstance(job, dict):
raise RuntimeError(
f"sd-server img_gen returned an unexpected submit response type: {type(job)}"
)
job_id = job.get("id")
if not job_id:View on GitHub (pinned to 203007d190)
Solutions
- Inspect the attached log tail/exception for the crash reason before retrying.
- Restart the server, then resubmit the job once.
- If it recurs on the same input, minimize the trigger (drop LoRAs, lower resolution) and capture the server stderr — it is a server-side crash, not client misuse.
Defensive patterns
Strategy: retry
Try / catch
try:
blobs = server.img_gen(payload, ...)
except RuntimeError as e:
if "connection lost during img_gen submit" in str(e):
capture_server_tail(e)
server = restart_server()
blobs = server.img_gen(payload, ...)
raise Prevention
- Treat submit-time transport errors as server death until proven otherwise.
- Capture server stderr continuously so crash causes are available on retry.
- Reduce submit payload size (fewer LoRAs) if crashes correlate with large requests.
When it happens
Trigger: Server process dies (OOM, segfault loading a LoRA, watchdog kill) between the alive-check and the POST, or during a slow submit; connection reset by peer surfaces as this error.
Common situations: Large payloads (many LoRAs, high-res params) making submit slow while the server crashes; memory pressure killing the server mid-request.
Related errors
- failed to spawn sd-server: {self._spawn_error}
- sd-server failed to become ready. Last output: {tail[:2000]}
- sd-server is not running.
- sd-server job queue is full (HTTP 429).
- sd-server img_gen submit -> {resp.status_code}: {resp.text[:
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/c40a2a768008c199.
Report an issue: GitHub.