Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clerk-js): Reduce retries for /tokens on 5xx errors #5106

Closed
wants to merge 2 commits into from

Conversation

anagstef
Copy link
Member

@anagstef anagstef commented Feb 8, 2025

Description

When requesting a token from FAPI on /tokens, we retry 4 times if the response is NOT a 4xx error.

We want to also stop retrying on 5xx errors.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Feb 8, 2025

🦋 Changeset detected

Latest commit: fea2b19

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

This PR includes changesets to release 19 packages
Name Type
@clerk/clerk-js Patch
@clerk/shared Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue 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

Copy link

vercel bot commented Feb 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 11, 2025 0:12am

@anagstef anagstef changed the title fix(clerk-js): Reduce retries for /tokens on 500 errors fix(clerk-js): Reduce retries for /tokens on 5xx errors Feb 8, 2025
@@ -85,7 +85,8 @@ export class Session extends BaseResource implements SessionResource {

getToken: GetToken = async (options?: GetTokenOptions): Promise<string | null> => {
return runWithExponentialBackOff(() => this._getToken(options), {
shouldRetry: (error: unknown, currentIteration: number) => !is4xxError(error) && currentIteration < 4,
shouldRetry: (error: unknown, currentIteration: number) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really not want to retry on 5xx at all? Traditionally retrying on 5xx is common practice in the case of intermittent errors, but I do see the risk with potentially making the underlying problem worse.

Copy link
Member

@LauraBeatris LauraBeatris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the case of FAPI going down, and the first call to /tokens fail with a 5xx, but the subsequential ones might succeed once the server normalizes

Maybe instead of not retrying at all, we can throttle with a larger delay?

@anagstef
Copy link
Member Author

Closing this in favor of another solution we are already working on!

@anagstef anagstef closed this Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants