Skip to content

Conversation

wunameya
Copy link
Contributor

@wunameya wunameya commented Sep 7, 2025

Support custom retryable exceptions via @RetryableException.
Fixes #1362

Summary by CodeRabbit

  • New Features
    • Added support for application-defined retriable exceptions. If a server-side exception is marked as retryable, the client will automatically retry the call with another provider according to the existing retry policy.
    • Introduced a dedicated error type for application-triggered retries to improve logging and observability.
    • Enablement is simple: annotate your exception class to have failures retried without changing client code.

@sofastack-cla sofastack-cla bot added cla:yes CLA is ok size/S labels Sep 7, 2025
Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

Walkthrough

Introduces a provider-side annotation to mark exceptions as retryable, maps such exceptions to a new CUSTOMER_RETRY_ERROR type, and adds client-side logic to retry invocations when this error is returned. No public API signatures changed beyond adding the new annotation and error constant.

Changes

Cohort / File(s) Summary of changes
Client failover retry handling
core-impl/client/src/main/java/com/alipay/sofa/rpc/client/FailoverCluster.java
After receiving a response, detects SofaRpcException with error type CUSTOMER_RETRY_ERROR in appResponse, increments retry counter, and continues to next provider.
Provider-side retry mapping
core/api/src/main/java/com/alipay/sofa/rpc/filter/ProviderInvoker.java
On InvocationTargetException, if the cause class is annotated with @RetryableException, wrap it in SofaRpcException(CUSTOMER_RETRY_ERROR); otherwise return the original cause as app response.
Retryable annotation
core/common/src/main/java/com/alipay/sofa/rpc/common/annotation/RetryableException.java
Adds new public marker annotation @RetryableException (RUNTIME retention, TYPE target, documented).
Error type extension
core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java
Adds public static final int CUSTOMER_RETRY_ERROR = 300; to represent user-defined retriable exceptions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor C as Client
  participant FC as FailoverCluster
  participant P as ProviderInvoker
  participant S as Service Impl

  rect rgb(245,248,255)
    C->>FC: invoke(request)
    loop per attempt until max
      FC->>P: invoke(request)
      P->>S: method call
      alt Service throws @RetryableException cause
        S-->>P: throws InvocationTargetException(cause)
        P-->>FC: SofaRpcException(type=CUSTOMER_RETRY_ERROR)
        note over FC: Detects CUSTOMER_RETRY_ERROR<br/>increments retry count
        FC-->>P: retry with next provider
      else Non-retryable exception or success
        S-->>P: return or non-retryable error
        P-->>FC: response/appResponse
        FC-->>C: return
      end
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Support retry for custom exceptions (#1362)
Provide a mechanism to mark exceptions as retriable (#1362)
Client retries when provider signals retriable exception (#1362)
Backward compatibility concerns clarified (#1362) No explicit compatibility tests or guards observed.

Assessment against linked issues: Out-of-scope changes

(no out-of-scope functional changes detected)

Suggested reviewers

  • EvenLjj
  • chuailiwu

Poem

A bunny taps the call, hop-hop—try again!
Marked by a gentle tag, “retry” says when.
Providers toss a hint, clients loop with care,
Across the fields of RPC, resilience fills the air.
With 300’s subtle nudge, we bound without fright—
Carrots queued, requests renewed, all night. 🥕✨

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


📜 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 bff6d8d and 6916e2e.

📒 Files selected for processing (1)
  • core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java
⏰ 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). (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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.

@sofastack-cla sofastack-cla bot added size/M and removed size/S labels Sep 7, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java (1)

111-114: Rename constant and add a dedicated 300-range section header.

“CUSTOMER” reads as end-user; here it’s “custom.” Also keep sectioning consistent with 100–199/200–299 blocks.

Apply:

-    /**
-     * 用户自定义可重试异常
-     */
-    public static final int CUSTOMER_RETRY_ERROR = 300;
+    // ==== 应用/业务可重试异常码 300-399 ======
+    /**
+     * 用户自定义可重试异常
+     */
+    public static final int CUSTOM_RETRY_ERROR      = 300;
core-impl/client/src/main/java/com/alipay/sofa/rpc/client/FailoverCluster.java (1)

70-78: Use the renamed error constant; logic otherwise looks good.

Keeps retries bounded and preserves existing logging behavior.

Apply:

-                    if (appResponse instanceof SofaRpcException) {
-                        if (((SofaRpcException) appResponse).getErrorType() == RpcErrorType.CUSTOMER_RETRY_ERROR) {
+                    if (appResponse instanceof SofaRpcException) {
+                        if (((SofaRpcException) appResponse).getErrorType() == RpcErrorType.CUSTOM_RETRY_ERROR) {
                             time++;
                             throwable = (SofaRpcException) appResponse;
                             continue;
                         }
                     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a11a24 and bff6d8d.

📒 Files selected for processing (4)
  • core-impl/client/src/main/java/com/alipay/sofa/rpc/client/FailoverCluster.java (1 hunks)
  • core/api/src/main/java/com/alipay/sofa/rpc/filter/ProviderInvoker.java (2 hunks)
  • core/common/src/main/java/com/alipay/sofa/rpc/common/annotation/RetryableException.java (1 hunks)
  • core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: build
core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java

[error] 1-1: Uncommitted changes detected. Please commit core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java before continuing.

⏰ 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). (1)
  • GitHub Check: sca
🔇 Additional comments (1)
core/exception/src/main/java/com/alipay/sofa/rpc/core/exception/RpcErrorType.java (1)

111-114: Fix CI: commit this file.

CI reports “Uncommitted changes detected” for this path. Ensure the modified file is added and committed to the PR.

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.

Support custom exception retry
1 participant