Skip to content

feat: Socket automatic retry as the same of that of python-sdk#307

Open
Abishek-Newar wants to merge 2 commits intoopenfga:mainfrom
Abishek-Newar:socker-hang-up
Open

feat: Socket automatic retry as the same of that of python-sdk#307
Abishek-Newar wants to merge 2 commits intoopenfga:mainfrom
Abishek-Newar:socker-hang-up

Conversation

@Abishek-Newar
Copy link
Contributor

@Abishek-Newar Abishek-Newar commented Jan 23, 2026

Description

Network errors like "socket hang up" are not being automatically retried by the SDK, even though the retry mechanism exists. Users expect transient network failures to be handled gracefully without requiring explicit configuration.

What problem is being solved?

The SDK now uses the default retry parameters (maxRetry: 3, minWaitInMs: 100) when the user doesn't explicitly provide retryParams in their configuration.

How is it being solved?

What changes are made to solve it?

  • common.ts : Changed the fallback values for maxRetry and minWaitInMs from 0 to SdkConstants.DefaultMaxRetry (3) and SdkConstants.DefaultMinWaitInMs (100ms) respectively.
  • tests/client.test.ts : Updated one test that expects an immediate 500 error to explicitly disable retries, since the test mock only provides a single response.

With this change, the SDK will automatically retry:

  1. Network errors (socket hang up, connection reset, etc.)
  2. HTTP 429 (Rate Limit Exceeded)
  3. HTTP 5xx errors (except 501)

References

Closes #305 #306

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced default retry behavior with improved default values for maximum retry attempts and minimum wait times between retries, providing more robust handling of transient failures.

✏️ Tip: You can customize this high-level summary in your review settings.

@Abishek-Newar Abishek-Newar requested a review from a team as a code owner January 23, 2026 11:56
@dosubot
Copy link

dosubot bot commented Jan 23, 2026

Related Documentation

Checked 5 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The PR updates default retry configuration in the request creation function to use SDK constants instead of zero values, enabling automatic retry behavior with non-zero minimum wait times by default. A corresponding test is updated to explicitly disable retries when testing expected failures.

Changes

Cohort / File(s) Summary
Retry Configuration Defaults
src/common.ts
Updated createRequestFunction to set default maxRetry to SdkConstants.DefaultMaxRetry and minWaitInMs to SdkConstants.DefaultMinWaitInMs instead of 0, enabling retry functionality when retryParams is undefined.
Test Updates
tests/client.test.ts
Modified listRelations test call to include explicit retryParams: { maxRetry: 0 } option, aligning test expectations with the new default retry behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • Socket Hang up Automatic retry #306: The default retry parameter changes directly enable automatic retries in the SDK, addressing the issue's request for retry functionality to be active by default rather than requiring explicit configuration.

Suggested reviewers

  • ewanharris
  • rhamzeh
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enabling automatic retry for socket errors by applying default retry parameters consistent with python-sdk behavior.
Linked Issues check ✅ Passed The PR directly addresses issue #305 by enabling default retries (maxRetry: 3, minWaitInMs: 100) that will retry socket hang up errors along with HTTP 429 and 5xx errors, meeting the requirement that such transient errors be retried automatically under default SDK settings.
Out of Scope Changes check ✅ Passed All changes are directly scoped to enabling default retry behavior: modifying default retry parameters in common.ts and updating a test to explicitly disable retries where only a single response is mocked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@Abishek-Newar
Copy link
Contributor Author

Hi @dyeam0 @SoulPancake , Please review it

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.67%. Comparing base (a7090e2) to head (3182389).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #307   +/-   ##
=======================================
  Coverage   89.67%   89.67%           
=======================================
  Files          25       25           
  Lines        1492     1492           
  Branches      279      256   -23     
=======================================
  Hits         1338     1338           
  Misses         94       94           
  Partials       60       60           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SDK’s retry behavior so that when users do not explicitly configure retryParams, requests will use the SDK’s default retry settings (3 retries with a 100ms minimum backoff), enabling automatic retries for transient failures like socket hang-ups.

Changes:

  • Use SdkConstants.DefaultMaxRetry / SdkConstants.DefaultMinWaitInMs as the fallback retry configuration in createRequestFunction.
  • Update a listRelations test to explicitly disable retries (maxRetry: 0) because the test only mocks a single 500 response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
common.ts Switches retry fallback values from 0 to SDK defaults so retries are enabled by default when not configured.
tests/client.test.ts Disables retries for a test case that expects a single 500 response to fail immediately.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@SoulPancake SoulPancake left a comment

Choose a reason for hiding this comment

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

Can you please also add a test for network error retries too?

const maxRetry: number = retryParams?.maxRetry ?? SdkConstants.DefaultMaxRetry;
const minWaitInMs: number = retryParams?.minWaitInMs ?? SdkConstants.DefaultMinWaitInMs;

const start = performance.now();
Copy link
Member

Choose a reason for hiding this comment

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

const maxRetry: number = retryParams ? retryParams.maxRetry : 0;

Can you also add it for the streaming requests

user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
object: "workspace:1",
relations: ["admin", "guest", "reader", "viewer"],
});
Copy link
Member

Choose a reason for hiding this comment

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

The test change here is defensive (preventing flake) rather than assertive

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.

socket hang up is not retried

3 participants