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
throw InterruptedException in FailoverClusterInvoker #10188
Comments
Just in my opinitions,for consumers, exceptions thrown by providers during business operations can be converted to business exceptions. |
|
写了一个简单的代码模拟下: public static void main(String[] args) throws InterruptedException {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
Future<?> submit = threadPoolExecutor.submit(() -> {
System.out.println("before: " + Thread.currentThread().isInterrupted());
dubboInvoke();
System.out.println("end: " + Thread.currentThread().isInterrupted());
});
Thread.sleep(1000);
submit.cancel(true);
}
static void dubboInvoke() {
try {
interruptError();
} catch (Exception e) {
//retry invoke
}
}
static void interruptError() throws Exception {
try {
Thread.sleep(5000);
System.out.println("wake up");
} catch (Exception e) {
//contains interrupt exception(RpcException)
throw e;
}
} 控制台输出信息: before: false
end: false invoke产生的InterruptException没有被抛出, 外层通过 Thread.currentThread().isInterrupted() 方法是感知不到的 |
这里应该在 catch 异常的时候将线程的 isInterrupted 状态置上去,如果目前 Dubbo 没有做的话也需要完善下 |
看了下源代码是没有做个操作的,所以写了这个pr #10164 , 我觉得核心是用户主动打断产生的异常, 不应该被重试(即使设置了重试次数) |
#10164 的问题是 InterruptedException.class 这个异常可能是服务端抛出来的异常(即是业务异常),不一定是客户端的异常。所以直接判断 cause 为 InterruptedException 是有问题的。 |
也有道理, 那就只能想办法来判断错误发生在客户端还是服务端了 |
@happytimor 从 isInterrupted 状态 + InterruptedException.class 理论上是可以判断的,你可以试试 |
我试下 |
@AlbumenJ debug看了下,服务端的异常不会出现在RpcException里面, 对于dubbo来说, 这是一个正常的返回 |
你可以试下服务端请求中,Filter 里面抛出 InterruptedException |
最近开发一个类似流程任务的一个功能, 核心就是在线程池里运行任务, 代码如下:
后来业务需要进行支持中断操作, 于是调整代码如下:
运行后发现任务无法被中断,查了下,发现最终是因为startTask方法里面的dubbo调用有设置重试次数(大部分时间是需要重试),failover策略会把InterruptException当做普通异常,直接重试了(打断失败)。
我觉得应该把InterruptException直接抛出来, 于是做了一个pr如下: #10164
想问下:
The text was updated successfully, but these errors were encountered: