Skip to content

Commit

Permalink
Fix: sendResponse if RpcRequestProcessor.doProcess throw Throwable (#334
Browse files Browse the repository at this point in the history
)

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

* update unit test

* update unit test
  • Loading branch information
JoeCqupt authored Apr 16, 2024
1 parent 138f9e4 commit 0d576a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ public void run() {
//protect the thread running this task
String remotingAddress = RemotingUtil.parseRemoteAddress(ctx.getChannelContext()
.channel());
logger
.error(
"Exception caught when process rpc request command in RpcRequestProcessor, Id="
+ msg.getId() + "! Invoke source address is [" + remotingAddress
+ "].", e);
String errMsg = "Exception caught when process rpc request command in RpcRequestProcessor, Id="
+ msg.getId();
logger.error(errMsg + "! Invoke source address is [" + remotingAddress + "].", e);
sendResponseIfNecessary(ctx, msg.getType(), getCommandFactory()
.createExceptionResponse(msg.getId(), e, errMsg));
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/alipay/remoting/rpc/exception/ExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,26 @@ public Executor getExecutor() {
latch.await();
Assert.assertEquals(InvokeServerException.class, ret.get(0).getClass());
}

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

RequestBody req = new RequestBody(4, "hello world");
Object result = null;
try {
result = client.invokeSync(addr, req, 3000);
String errMsg = "Should throw InvokeServerException!";
logger.error(errMsg);
Assert.fail(errMsg);
} catch (Exception e) {
Assert.assertNull(result);
Assert.assertEquals(InvokeServerException.class, e.getClass());
}
}
}

0 comments on commit 0d576a6

Please sign in to comment.