Skip to content

fix(query-core): reject when a 'retry' or 'retryDelay' function throws - #12127

Open
koreahghg wants to merge 1 commit into
TanStack:mainfrom
koreahghg:fix/retryer-throwing-retry-callbacks
Open

koreahghg wants to merge 1 commit into
TanStack:mainfrom
koreahghg:fix/retryer-throwing-retry-callbacks

Conversation

@koreahghg

@koreahghg koreahghg commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

If a retry or retryDelay function throws, the retryer never settles. The query stays in fetchStatus: 'fetching' forever, is never garbage collected, and later refetches reuse the same stuck promise. A mutation in a scope also blocks every mutation queued after it.

This happens with a common pattern like:

retry: (count, error) => error.response.status !== 404 && count < 3

A network error has no response, so this throws a TypeError.

The fix wraps both calls in a try/catch and rejects with the thrown error. I used the callback's error instead of the original one so the mistake in the callback shows up instead of being hidden. This matches how a synchronous throw from fn is handled.

Added two tests to retryer.test.tsx. Without the fix they time out.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Queries and mutations now reject with the error if a retry or retryDelay callback throws, instead of remaining pending and fetching.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f9f0563

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/lit-query Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-devtools Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Patch
@tanstack/eslint-plugin-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/query/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b7e9f6a-265c-4e96-83d8-4a132062302e
📥 Commits

Reviewing files that changed from the base of the PR and between 959f65e and f9f0563.

📒 Files selected for processing: 3
  • .changeset/reject-on-throwing-retry-callback.md
  • packages/query-core/src/__tests__/retryer.test.tsx
  • packages/query-core/src/retryer.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The retryer now catches errors thrown by retry and retryDelay callbacks and rejects with those errors. Tests cover both cases, and a patch changeset records the change.

Changes: Retry Callback Error Handling

Layer / File(s) Summary
Catch and reject callback errors
packages/query-core/src/retryer.ts, packages/query-core/src/__tests__/retryer.test.tsx, .changeset/reject-on-throwing-retry-callback.md
createRetryer rejects when retry or retryDelay throws. Tests verify the rejection and retryer status. A patch changeset describes the behavior.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: sukvvon

Merge Risk: ⚪ Minimal · up to f9f05

Queries and mutations now reject when a retry or retryDelay callback throws, instead of staying pending indefinitely. No merge-blocking risk is evident.

Pre-merge checks: Passed 5
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely identifies the main change: rejecting when retry or retryDelay callbacks throw.
Description check Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the issue, motivation, implementation, tests, and changeset, and it marks the relevant checklist item…
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description includes the required Changes, Checklist, and Release Impact sections. It explains the issue, motivation, implementation, tests, and changeset, and it marks the relevant checklist items complete.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@koreahghg
koreahghg marked this pull request as ready for review October 19, 2026 06:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant