{"record":{"id":"c40a2a768008c199","repo":"unslothai/unsloth","slug":"sd-server-connection-lost-during-img-gen-submit","errorCode":null,"errorMessage":"sd-server connection lost during img_gen submit","messagePattern":"sd-server connection lost during img_gen submit","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/sd_cpp_server.py","lineNumber":464,"sourceCode":"        Raises ``RuntimeError`` on submit/poll failures (including the server dying), with\n        the log tail attached.\n        \"\"\"\n        # Already stopped with the cancel event set: report cancellation (route 409), not a generic \"server died\" 500.\n        if self._stopped or not self.is_alive():\n            if cancel_event is not None and cancel_event.is_set():\n                raise SdCppCancelled(\"sd-server generation was cancelled.\")\n            raise RuntimeError(\"sd-server is not running.\")\n\n        self._step_listener = on_step\n        job_id: Optional[str] = None\n        try:\n            # Submit -> 202 Accepted + job id.\n            try:\n                resp = self._client.post(\n                    f\"{self.base_url}{_IMG_GEN_PATH}\", json = payload, timeout = submit_timeout\n                )\n            except (*_TRANSPORT_ERRORS, httpx.TimeoutException) as exc:\n                raise RuntimeError(self._died_message(\"img_gen submit\", exc)) from exc\n            if resp.status_code == 429:\n                raise RuntimeError(\"sd-server job queue is full (HTTP 429).\")\n            if resp.status_code not in (200, 202):\n                raise RuntimeError(\n                    f\"sd-server img_gen submit -> {resp.status_code}: {resp.text[:500]}\"\n                )\n            try:\n                job = resp.json()\n            except ValueError as exc:\n                raise RuntimeError(\n                    f\"sd-server img_gen returned a non-JSON submit response: {exc}\"\n                ) from exc\n            if not isinstance(job, dict):\n                raise RuntimeError(\n                    f\"sd-server img_gen returned an unexpected submit response type: {type(job)}\"\n                )\n            job_id = job.get(\"id\")\n            if not job_id:","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/sd_cpp_server.py#L446-L482","documentation":"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.","triggerScenarios":"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.","commonSituations":"Large payloads (many LoRAs, high-res params) making submit slow while the server crashes; memory pressure killing the server mid-request.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    blobs = server.img_gen(payload, ...)\nexcept RuntimeError as e:\n    if \"connection lost during img_gen submit\" in str(e):\n        capture_server_tail(e)\n        server = restart_server()\n        blobs = server.img_gen(payload, ...)\n    raise","preventionTips":["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."],"tags":["diffusion","sd-cpp","server","network","crash"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}