Skip to content

fix: sync back timeout and batchCheck fixes - #571

Closed
jimmyjames wants to merge 1 commit into
mainfrom
fix/java-http-fixes
Closed

fix: sync back timeout and batchCheck fixes#571
jimmyjames wants to merge 1 commit into
mainfrom
fix/java-http-fixes

Conversation

@jimmyjames

@jimmyjames jimmyjames commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Sync back some http java fixes

References

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

  • New Features

    • Added support for configuring HTTP client connection timeouts during API client initialization.
  • Bug Fixes

    • Improved error handling and synchronization in batch check operations to better propagate failures.
  • Tests

    • Added a new test to verify correct handling of rate-limited (HTTP 429) responses during batch check requests.

@jimmyjames
jimmyjames requested a review from a team as a code owner July 15, 2025 20:22
@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce connection timeout configuration in the Java API client constructors and improve error handling in the batchCheck method. Additionally, a new test is added to verify correct behavior when the batch-check endpoint is rate-limited.

Changes

File(s) Change Summary
config/clients/java/template/libraries/native/api.mustache Modified OpenFgaApi constructor to set HTTP client connection timeout from configuration.
config/clients/java/template/src/main/api/auth/OAuth2Client.java.mustache Updated OAuth2Client constructor to propagate connectTimeout to its internal configuration.
config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache Refactored batchCheck method for improved error handling and synchronization using whenComplete and try-finally.
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache Added batchCheck_rateLimited test to verify rate-limiting and error propagation in batch-check requests.

Sequence Diagram(s)

sequenceDiagram
    participant Test as OpenFgaClientTest
    participant Client as OpenFgaClient
    participant HTTP as HttpClient
    Test->>Client: batchCheck(request)
    Client->>HTTP: POST /batch-check
    HTTP-->>Client: HTTP 429 Rate Limited
    Client-->>Test: ExecutionException (FgaApiRateLimitExceededError)
Loading

Suggested labels

codex

Suggested reviewers

  • rhamzeh

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcf33df and 0f73aaf.

📒 Files selected for processing (4)
  • config/clients/java/template/libraries/native/api.mustache (1 hunks)
  • config/clients/java/template/src/main/api/auth/OAuth2Client.java.mustache (1 hunks)
  • config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache (3 hunks)
  • config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-test-java-sdk
  • GitHub Check: build-and-test-go-sdk
🔇 Additional comments (7)
config/clients/java/template/src/main/api/auth/OAuth2Client.java.mustache (1)

43-43: LGTM: Connection timeout configuration added consistently.

The addition of .connectTimeout(configuration.getConnectTimeout()) follows the existing builder pattern and is consistent with other configuration properties being set in the constructor.

config/clients/java/template/libraries/native/api.mustache (1)

91-94: LGTM: Proper connection timeout configuration with defensive null checking.

The implementation correctly:

  • Retrieves the connection timeout from configuration
  • Performs null checking to avoid potential NPE
  • Applies the timeout to the HTTP client builder using the fluent API
  • Follows good defensive programming practices
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (1)

2060-2083: Well-structured test for rate limiting behavior.

This test effectively validates that the batchCheck method properly handles rate-limited responses (HTTP 429). The test correctly:

  • Mocks the HTTP client to return a 429 status with appropriate error message
  • Creates a proper test request with correlation ID
  • Verifies the expected exception type and retry behavior
  • Checks that retries are attempted according to the configured DEFAULT_MAX_RETRIES

The test follows the established patterns in the file and provides good coverage for rate limiting scenarios.

config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache (4)

18-18: LGTM! Required import for AtomicReference.

The import is necessary for the new failure tracking mechanism in the batchCheck method.


703-703: LGTM! Thread-safe failure tracking for batch operations.

The AtomicReference ensures thread-safe capture of the first failure encountered during parallel batch check operations.


724-746: Excellent improvement to error handling and synchronization.

The refactoring from handleAsync().thenAccept().thenRun() to whenComplete() with a try-finally block provides several benefits:

  1. Guaranteed cleanup: The finally block ensures latch.countDown() is always called, preventing potential deadlocks
  2. Proper error propagation: failure.compareAndSet(null, throwable) captures the first failure while avoiding race conditions
  3. Simplified control flow: Single callback reduces complexity compared to chained operations

The implementation correctly handles both success and failure cases while maintaining thread safety.


751-753: LGTM! Proper failure propagation after synchronization.

The failure check after latch.await() correctly propagates any captured exceptions, ensuring that the first failure encountered during batch processing is properly returned to the caller.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rhamzeh
rhamzeh added this pull request to the merge queue Jul 15, 2025
@rhamzeh
rhamzeh removed this pull request from the merge queue due to a manual request Jul 15, 2025
@jimmyjames

Copy link
Copy Markdown
Contributor Author

replaced with #572

@jimmyjames jimmyjames closed this Jul 15, 2025
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.

2 participants