bug: retry.fetch ignores the caller's abort signal and retries aborted requests
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:
- Aborting
init.signalmid-request is retried as a timeout.retryFetchcan't tell the caller'sAbortErrorfrom its owntimeoutInMs, so it waits out the backoff and sends the request again, and the resend can't be aborted. - The signal of a
Requestinput is ignored.retryFetchonly listens toinit.signal. - A signal that is already aborted still sends the request, because its
abortevent 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.
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!
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.signalor theRequestinput - rejects immediately when the signal is already aborted (no request sent)
- does not retry caller-initiated
AbortErroras 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.)