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: sendResponse if RpcRequestProcessor.doProcess throw Throwable #334

Merged
merged 3 commits into from
Apr 16, 2024

Conversation

JoeCqupt
Copy link
Contributor

@JoeCqupt JoeCqupt commented Dec 14, 2023

Fix: sendResponse if RpcRequestProcessor.doProcess throw Throwable in ProcessTask

reproduce problem

class ExceptionTest

 @Test
    public void testGetBizClassLoaderException1() {
        server.registerUserProcessor(new SimpleServerUserProcessor() {
            @Override
            public ClassLoader getBizClassLoader() {
                throw new RuntimeException("getBizClassLoader fail.");
            }
        });

        RequestBody req = new RequestBody(4, "hello world");
        try {
            client.invokeSync(addr, req, 3000);
        } catch (InvokeServerException e) {
            Assert.assertTrue(true);
        } catch (RemotingException e) {
            String errMsg = "RemotingException in testGetBizClassLoaderException1";
            logger.error(errMsg);
            Assert.fail(errMsg);
        } catch (InterruptedException e) {
            String errMsg = "InterruptedException caught in testGetBizClassLoaderException1";
            logger.error(errMsg, e);
            Assert.fail(errMsg);
        }
    }

we except get InvokeServerException when userProcessor.getBizClassLoader throw exception.
but we get InvokeTimeoutException
image

The Reason

https://github.com/sofastack/sofa-bolt/blob/master/src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java#L395

RpcRequestProcessor#ProcessTask did not handle Throwable.

Summary by CodeRabbit

  • Refactor
    • Improved the error logging mechanism for enhanced clarity and consistency in handling RPC requests.
  • Tests
    • Added tests for handling exceptions when accessing the business class loader, ensuring robust error management.

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Dec 14, 2023

PTAL @OrezzerO @nobodyiam

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Dec 14, 2023

I try to explore why .

maybe this comment show the reason :

https://github.com/sofastack/sofa-bolt/blob/master/src/main/java/com/alipay/remoting/rpc/protocol/RpcCommandHandler.java#L163

but

  1. I still think sending an ack response is necessary way of handling exceptions
  2. Duplicate ack responses will be ignored by the client

@nobodyiam
Copy link
Member

I agree a clear response is necessary way of handling exceptions. @chuailiwu would you please help to take a look?

@OrezzerO
Copy link
Collaborator

Do agree that a clear response is necessary.

As the comment said Other exceptions should be processed where exception was caught, because here we don't known whether ack had been sent back, I think it's fine to handle exception in ProcessTask.run, if they are throw to ProcessTask.run ,which means they are not handled in inner methods.

Copy link

coderabbitai bot commented Apr 1, 2024

Walkthrough

The recent update focuses on refining the error logging mechanism within the RpcRequestProcessor's run method, enhancing both clarity and consistency. Additionally, a new method, sendResponseIfNecessary, has been introduced to better manage exceptions. In the testing domain, a new method, testGetBizClassLoaderException1, has been added to scrutinize different exception scenarios related to the business class loader, further fortifying the robustness of exception handling.

Changes

Files Change Summaries
.../rpc/protocol/RpcRequestProcessor.java Refactored error logging, added sendResponseIfNecessary method for exception scenarios.
.../rpc/exception/ExceptionTest.java Added testGetBizClassLoaderException1 for testing RuntimeException scenarios in class loading.

🐰✨
In the land of code, where the binaries roam,
Changes were made, in the processor's home.
"Log the errors," the Rabbit decreed,
And test the exceptions, for quality we need.
With a hop and a skip, the updates were done,
In the quest for stability, another victory won.
🌟📜🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

@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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 829be55 and 2bc30fb.
Files selected for processing (2)
  • src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java (1 hunks)
  • src/test/java/com/alipay/remoting/rpc/exception/ExceptionTest.java (1 hunks)
Additional Context Used
Additional comments not posted (1)
src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java (1)

398-402: The error handling and response sending logic in the ProcessTask's run method has been updated to ensure that a response is sent back in case of exceptions. This change aligns with the PR objectives and improves the robustness of the error handling mechanism. However, consider adding more context to the error message, such as the type of exception caught, to aid in debugging.


RequestBody req = new RequestBody(4, "hello world");
try {
client.invokeSync(addr, req, 3000);
Copy link

Choose a reason for hiding this comment

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

To ensure the test fails if client.invokeSync does not throw an exception, add Assert.fail(); after this line. This change makes the test's intention clearer and ensures it properly fails when the expected exception is not thrown.

+            Assert.fail("Expected InvokeServerException was not thrown.");

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
client.invokeSync(addr, req, 3000);
client.invokeSync(addr, req, 3000);
Assert.fail("Expected InvokeServerException was not thrown.");

logger.error(errMsg);
Assert.fail(errMsg);
} catch (InvokeServerException e) {
Assert.assertTrue(true);
Copy link

Choose a reason for hiding this comment

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

The assertion Assert.assertTrue(true); is redundant and does not contribute to the test's effectiveness. Consider removing it or replacing it with a more meaningful assertion, such as checking the message or type of the caught exception if applicable.

-            Assert.assertTrue(true);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Assert.assertTrue(true);

Copy link

@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: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2bc30fb and 32d7b4a.
Files selected for processing (1)
  • src/test/java/com/alipay/remoting/rpc/exception/ExceptionTest.java (1 hunks)

Copy link
Collaborator

@OrezzerO OrezzerO left a comment

Choose a reason for hiding this comment

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

LGTM

@chuailiwu chuailiwu merged commit 0d576a6 into sofastack:master Apr 16, 2024
3 checks passed
JoeCqupt added a commit to JoeCqupt/sofa-bolt that referenced this pull request Jun 5, 2024
…ofastack#334)

* fix: sendResponse if RpcRequestProcessor.doProcess throw Throwable in ProcessTask

* update unit test

* update unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants