diffusers: generation continues after client disconnect and blocks the event loop — no cancellation

Offen
#1,041 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python
Bereich
ai, api, backend

Rechercherichtung

Beginne in python/diffusers_server/server.py am create_image-Endpunkt und seinem synchronen generate_images-Aufruf. Vergleiche das Verhalten bei der Abbruchbehandlung des Request-Kontexts im llama.cpp-Chatpfad und reproduziere eine Client-Trennung während des Modellladens oder der Generierung. Die Aufgabe ist erledigt, wenn abgebrochene Arbeiten beendet werden oder ausdrücklich als nicht abbrechbar dokumentiert sind, ohne nachfolgende Anfragen dahinter zu blockieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Description

The diffusers backend does not cancel image generation when the requesting client disconnects. A request whose client has timed out or closed the connection still runs to completion — model load included — and the response is written to a socket nobody reads. Subsequent requests queue behind these abandoned jobs, so client-side retries (the natural reaction to a timeout) compound the problem instead of recovering from it.

Likely mechanism (from source)

In python/diffusers_server/server.py, create_image is an async def endpoint that calls the synchronous generate_images pipeline directly — no thread executor, no request.is_disconnected() check, no cancellation path. The blocking call occupies the event loop for the full generation, so the server cannot observe the disconnect even in principle, and every other request serializes behind it.

Environment

  • Docker Model Runner v1.2.6 (Docker Desktop), macOS, Apple Silicon (M1 Pro, 16 GB). The handler is unchanged on current main and in v1.2.7/v1.2.8 release notes.
  • Model: stable-diffusion (DDUF, diffusers backend, MPS float16)

Steps to reproduce

  1. Ensure the diffusers runner is not resident (cold start), so the first request also pays the model load.
  2. POST /engines/diffusers/v1/images/generations with a client timeout shorter than load + generation (e.g. 120 s while the DDUF load alone takes 2+ min on a memory-pressured host).
  3. Let the client time out and close the connection. Send a second request from another client.

Observed

  • The first request's generation starts after its client is gone and runs to completion; the engine logs 200 OK to the disconnected socket. In one instance the host slept mid-queue and the engine completed the abandoned job ~6 hours after the client vanished, immediately on wake.
  • The second request waits behind the abandoned job and can itself time out having never started.
  • The abandoned work holds the model's residency (~7 GB for stable-diffusion) and the GPU for its full duration.

Expected

Client disconnect (or at minimum, connection close before generation starts) cancels the pending/running job — the behavior the llama.cpp chat path already exhibits via request context cancellation. Alternatively: a documented statement that diffusers jobs are uncancellable once accepted, so clients can choose long timeouts over retries.

Impact

Any client that enforces a per-request timeout (agent tool loops, gateways, proxies) turns one slow cold start into a pile-up: each timeout triggers a retry that queues behind a job whose consumer no longer exists.

Vorherrschende Sprache
Go
Sterne
665
Forks
161
Ø Merge
4 Std. 25 Min.
Gemergte PRs (30 T.)
18

Entwicklungsumgebung

  • Enthält ein Dockerfile oder eine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus docker/model-runner

Alle Issues in docker/model-runner

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.