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

BlockException#isBlockException使用场景支持message中含SentinelRpcException等的情况 #379

Closed
cdfive opened this issue Jan 4, 2019 · 1 comment
Labels
kind/enhancement Category issues or prs related to enhancement.
Milestone

Comments

@cdfive
Copy link
Collaborator

cdfive commented Jan 4, 2019

Issue Description

1.通过sentinel-dubbo-adapter埋点抛出了SentinelRpcException,Dubbo框架经过
com.alibaba.dubbo.common.utils.StringUtils.toString(SentinelRpcException)处理后抛出了RpcExceptionRuntimeException,这时在调用方捕获到RpcExceptionRuntimeException,用BlockException#isBlockException判断是false,Dubbo通过这个工具类处理是为了避免调用方法反序列化失败,但实际上发生了流控,能否考虑通过判断message的方式返回true呢?

2.BlockException类有如下定义和判断:

public static final String BLOCK_EXCEPTION_FLAG = "SentinelBlockException";
public static RuntimeException THROW_OUT_EXCEPTION = new RuntimeException(BLOCK_EXCEPTION_FLAG);

...
if ((cause instanceof BlockException) || (BLOCK_EXCEPTION_FLAG.equals(cause.getMessage()))) {
...

在工程中搜索,这个THROW_OUT_EXCEPTION并没有用到,也就是判断里不会走到后面那个或分支,为什么用这个cause.getMessage()和"SentinelBlockException"判断? 要不要把SentinelRpcException、BlockException、FlowException也加上

Describe what happened (or what feature you want)

测试代码:

// true
FlowException flowException = new FlowException("test");
System.out.println(BlockException.isBlockException(flowException));

// true
SentinelRpcException sentinelRpcException = new SentinelRpcException(flowException);
System.out.println(BlockException.isBlockException(sentinelRpcException));

// false
RuntimeException runtimeException = new RuntimeException(com.alibaba.dubbo.common.utils.StringUtils.toString(sentinelRpcException));
System.out.println(BlockException.isBlockException(runtimeException));

// false
RpcException rpcException = new RpcException(com.alibaba.dubbo.common.utils.StringUtils.toString(sentinelRpcException));
System.out.println(BlockException.isBlockException(rpcException));

Describe what you expected to happen

期望如果Message中有SentinelRpcException、FlowException、DegradeException、BlockException等,BlockException#isBlockException能返回true,这样便于dubbo在捕获异常,区分是Sentinel的流控异常;

但这样通过message判断是否合理,有没有更好的方式。

#374 在dubbo-demo的例子里也有此需求

@sczyh30 sczyh30 added the kind/enhancement Category issues or prs related to enhancement. label Jan 4, 2019
@sczyh30 sczyh30 added this to the 1.7.3 milestone Apr 8, 2020
@sczyh30 sczyh30 modified the milestones: 1.8.0, 1.8.1 Aug 3, 2020
@sczyh30
Copy link
Member

sczyh30 commented Jan 18, 2021

This has been resolved via #1680 (125996d)

IMHO SentinelRpcException should be deprecated. If the exception needs to be carried in RPC response, it should be warpped as RuntimeException.

Any suggestions? @cdfive @jasonjoo2010

@sczyh30 sczyh30 closed this as completed Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants