[GH-ISSUE #3059] [Issue]: RunPod ComfyUI generation ignores request.signal — the poll loop and provider fetches are not cancellable #1627

Closed
opened 2026-10-21 05:41:03 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3059

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

generateRunPodComfyUI never observes request.signal (the caller's abort / the withImageGenerationDeadline controller). The submit fetch and every status-poll fetch use a fresh AbortSignal.timeout(30_000), and the inter-poll delay is a bare setTimeout with no abort listener. So when a caller aborts (e.g. game-asset generation passes req.signal), the RunPod job keeps being polled and re-fetched for up to RUNPOD_MAX_POLLS (90) x 2s = 3 minutes. The awaited promise inside Promise.race([run, deadline]) cannot settle early on abort, so a user/game cancel does not stop the work. Every other backend in the subsystem threads the signal through; RunPod is the lone exception.

How to reproduce (try it yourself)

  1. Configure a runpod_comfyui image connection.
  2. Trigger a generation that supplies an abort signal (e.g. game asset generation passes req.signal).
  3. Abort/cancel the parent request while the RunPod job is IN_QUEUE/IN_PROGRESS.

You'll see: status-poll requests keep firing every 2s and the call does not return until the job completes or RunPod's internal 3-minute cap is reached — the cancellation is ignored.

Expected: an abort settles the call promptly and aborts any in-flight submit/status fetch.

Where it is

packages/server/src/services/image/runpod-comfyui.service.ts:

  • Submit fetch line ~129 — signal: AbortSignal.timeout(30_000).
  • Poll delay line 144 — await new Promise((r) => setTimeout(r, runPodPollIntervalMs())), no abort.
  • Status poll fetch line ~149 — signal: AbortSignal.timeout(30_000).
  • Whole function body lines 59-171 never reads request.signal.

For contrast, local ComfyUI uses sleepWithAbort(1000, request.signal) and imageRequestSignal(request) (image-generation.ts:2116/2135/2138/2167); A1111/Stability/Horde/etc. all thread imageRequestSignal(request). ImageGenRequest.signal is set by withImageGenerationDeadline (image-generation.ts:162-167).

What's happening

The poll delay uses an abort-unaware setTimeout, and each fetch builds its own AbortSignal.timeout(30_000) instead of combining with request.signal. Because the Promise.race only settles early if run reacts to the signal, and generateRunPodComfyUI ignores it, an external abort does not stop the loop.

Suggested fix

Thread request.signal into both fetches and the poll delay using self-contained local helpers (sleepWithAbort/imageRequestSignal/throwIfAborted are NOT exported from image-generation.ts, so do not import them — that would fail pnpm check):

  1. Add two helpers near runPodFetch:
function runPodFetchSignal(request: ImageGenRequest): AbortSignal {
  const timeout = AbortSignal.timeout(30_000);
  return request.signal ? AbortSignal.any([request.signal, timeout]) : timeout;
}
function runPodSleep(ms: number, signal?: AbortSignal): Promise<void> {
  return new Promise((resolve, reject) => {
    if (signal?.aborted) {
      reject(signal.reason instanceof Error ? signal.reason : new Error("RunPod generation aborted"));
      return;
    }
    const onAbort = () => {
      clearTimeout(timer);
      reject(signal?.reason instanceof Error ? signal.reason : new Error("RunPod generation aborted"));
    };
    const timer = setTimeout(() => {
      signal?.removeEventListener("abort", onAbort);
      resolve();
    }, ms);
    timer.unref?.();
    signal?.addEventListener("abort", onAbort, { once: true });
  });
}
  1. Submit fetch (~line 129): signal: AbortSignal.timeout(30_000) -> signal: runPodFetchSignal(request).
  2. Poll loop: replace the bare setTimeout delay with await runPodSleep(runPodPollIntervalMs(), request.signal);, and use signal: runPodFetchSignal(request) on the status fetch.

runPodSleep rejecting on abort makes the awaited race settle promptly with the deadline/caller reason; the combined fetch signal aborts in-flight requests. Keep the 2s interval, the 90-poll cap, and all error strings unchanged.

Regression avoided: the original suggestion said to reuse sleepWithAbort/imageRequestSignal, but those are not exported and importing them breaks the build — hence the self-contained local helpers. The no-signal direct-call path falls back to plain AbortSignal.timeout(30_000), mirroring imageRequestSignal's request.signal ?? AbortSignal.timeout(...) semantics. AbortSignal.any is available (Node 24) and already used elsewhere; safeFetch spreads ...init so the signal threads through. The change is isolated to this file and only adds signal observation.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3059 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** `generateRunPodComfyUI` never observes `request.signal` (the caller's abort / the `withImageGenerationDeadline` controller). The submit fetch and every status-poll fetch use a fresh `AbortSignal.timeout(30_000)`, and the inter-poll delay is a bare `setTimeout` with no abort listener. So when a caller aborts (e.g. game-asset generation passes `req.signal`), the RunPod job keeps being polled and re-fetched for up to `RUNPOD_MAX_POLLS` (90) x 2s = 3 minutes. The awaited promise inside `Promise.race([run, deadline])` cannot settle early on abort, so a user/game cancel does not stop the work. Every other backend in the subsystem threads the signal through; RunPod is the lone exception. **How to reproduce (try it yourself)** 1. Configure a `runpod_comfyui` image connection. 2. Trigger a generation that supplies an abort signal (e.g. game asset generation passes `req.signal`). 3. Abort/cancel the parent request while the RunPod job is `IN_QUEUE`/`IN_PROGRESS`. You'll see: status-poll requests keep firing every 2s and the call does not return until the job completes or RunPod's internal 3-minute cap is reached — the cancellation is ignored. Expected: an abort settles the call promptly and aborts any in-flight submit/status fetch. **Where it is** `packages/server/src/services/image/runpod-comfyui.service.ts`: - Submit fetch line ~129 — `signal: AbortSignal.timeout(30_000)`. - Poll delay line 144 — `await new Promise((r) => setTimeout(r, runPodPollIntervalMs()))`, no abort. - Status poll fetch line ~149 — `signal: AbortSignal.timeout(30_000)`. - Whole function body lines 59-171 never reads `request.signal`. For contrast, local ComfyUI uses `sleepWithAbort(1000, request.signal)` and `imageRequestSignal(request)` (image-generation.ts:2116/2135/2138/2167); A1111/Stability/Horde/etc. all thread `imageRequestSignal(request)`. `ImageGenRequest.signal` is set by `withImageGenerationDeadline` (image-generation.ts:162-167). **What's happening** The poll delay uses an abort-unaware `setTimeout`, and each fetch builds its own `AbortSignal.timeout(30_000)` instead of combining with `request.signal`. Because the `Promise.race` only settles early if `run` reacts to the signal, and `generateRunPodComfyUI` ignores it, an external abort does not stop the loop. **Suggested fix** Thread `request.signal` into both fetches and the poll delay using self-contained local helpers (`sleepWithAbort`/`imageRequestSignal`/`throwIfAborted` are NOT exported from image-generation.ts, so do not import them — that would fail `pnpm check`): 1. Add two helpers near `runPodFetch`: ```ts function runPodFetchSignal(request: ImageGenRequest): AbortSignal { const timeout = AbortSignal.timeout(30_000); return request.signal ? AbortSignal.any([request.signal, timeout]) : timeout; } function runPodSleep(ms: number, signal?: AbortSignal): Promise<void> { return new Promise((resolve, reject) => { if (signal?.aborted) { reject(signal.reason instanceof Error ? signal.reason : new Error("RunPod generation aborted")); return; } const onAbort = () => { clearTimeout(timer); reject(signal?.reason instanceof Error ? signal.reason : new Error("RunPod generation aborted")); }; const timer = setTimeout(() => { signal?.removeEventListener("abort", onAbort); resolve(); }, ms); timer.unref?.(); signal?.addEventListener("abort", onAbort, { once: true }); }); } ``` 2. Submit fetch (~line 129): `signal: AbortSignal.timeout(30_000)` -> `signal: runPodFetchSignal(request)`. 3. Poll loop: replace the bare `setTimeout` delay with `await runPodSleep(runPodPollIntervalMs(), request.signal);`, and use `signal: runPodFetchSignal(request)` on the status fetch. `runPodSleep` rejecting on abort makes the awaited race settle promptly with the deadline/caller reason; the combined fetch signal aborts in-flight requests. Keep the 2s interval, the 90-poll cap, and all error strings unchanged. Regression avoided: the original suggestion said to reuse `sleepWithAbort`/`imageRequestSignal`, but those are not exported and importing them breaks the build — hence the self-contained local helpers. The no-signal direct-call path falls back to plain `AbortSignal.timeout(30_000)`, mirroring `imageRequestSignal`'s `request.signal ?? AbortSignal.timeout(...)` semantics. `AbortSignal.any` is available (Node 24) and already used elsewhere; `safeFetch` spreads `...init` so the signal threads through. The change is isolated to this file and only adds signal observation. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064

<!-- gh-comment-id:4835429384 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3064 on branch codex/issue-sweep-3054-3063 (commit 3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835579007 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3064 on branch `codex/issue-sweep-3054-3063` (commit 3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1627
No description provided.