trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

bug: retry.fetch ignores the caller's abort signal and retries aborted requests

Open Suksham-sharma opened this issue 3 weeks ago • 2 comments

Provide environment information

@trigger.dev/sdk 4.8.4 (main at 1fec779), Node 24.4.1, macOS.

Describe the bug

retry.fetch doesn't stop when the caller aborts, unlike fetch:

  1. Aborting init.signal mid-request is retried as a timeout. retryFetch can't tell the caller's AbortError from its own timeoutInMs, so it waits out the backoff and sends the request again, and the resend can't be aborted.
  2. The signal of a Request input is ignored. retryFetch only listens to init.signal.
  3. A signal that is already aborted still sends the request, because its abort event never fires.

All three are in retryFetch in packages/trigger-sdk/src/v3/retry.ts.

Reproduction repo

N/A

To reproduce

Inside a task, against an endpoint that takes about 500ms to respond:

const a = new AbortController();
setTimeout(() => a.abort(), 100);
await retry.fetch(url, { signal: a.signal }); // resolves 200 after resending

const b = new AbortController();
setTimeout(() => b.abort(), 100);
await retry.fetch(new Request(url, { signal: b.signal })); // resolves 200

await retry.fetch(url, { signal: AbortSignal.abort() }); // sends the request, resolves 200

fetch rejects with AbortError in all three cases.

Suggested fix

Use init.signal, falling back to the Request's signal, link it to every attempt (including when it is already aborted), and don't retry an abort that came from it. I have this ready with tests.

Additional information

Found while working on #2490.

Suksham-sharma avatar Nov 11 '26 12:11 Suksham-sharma

Hi @Suksham-sharma,

I was looking into this issue and noticed you mentioned having a fix ready with tests. Are you planning to submit a PR for it?

I'd be interested in contributing if you haven't started the implementation yet, but I wanted to check first to avoid duplicating your work.

Thanks!

samarthyadavv avatar Nov 12 '26 23:11 samarthyadavv

I have a fix ready for this on my fork (PR was auto-closed for vouching):

https://github.com/umeraamir69/trigger.dev/tree/fix/retry-fetch-abort-5116 https://github.com/triggerdotdev/trigger.dev/pull/5127

It:

  • resolves the abort signal from init.signal or the Request input
  • rejects immediately when the signal is already aborted (no request sent)
  • does not retry caller-initiated AbortError as a timeout

Happy to reopen once vouched, or a maintainer can pull the branch. (@Suksham-sharma — if you already had a PR ready, feel free to take precedence.)

umeraamir69 avatar Nov 14 '26 06:11 umeraamir69