Repository navigation
Description
dubbo version: 2.5.6
issues code 1
@Component
public class ConsumerA {
@Reference(version = "1.0.0",retries = 0, timeout = 180000)
public ProviderB providerB ;
public void a(){
try{
providerB.b();
}catch(Exception e){
// do something
}
}
}
@Service(version = "1.0.0")
public class ProviderB {
public void b(){
try{
Thread.sleep(10000); //休眠10秒为了模拟程序执行缓慢
}catch(Exception e){
}
}
}使用场景,当B服务提供者需要紧急重启的情况下:
此时,B宕机,如何让a()立即捕获到异常信息,而不用等待3分钟才返回,如果大量并发请求在请求中,将可能造成A服务大量请求堆积。这个是否有更友好的办法去处理,或者,我的配置并不完善。
Usage Scenarios When the B Service Provider Needs an Emergency Restart:
At this point, B crashes, how to make a() immediately capture exception information without waiting for 3 minutes to return. If a large number of concurrent requests are in the request, it may cause a large number of A service requests to be accumulated. Is there a more friendly way to deal with this, or my configuration is not perfect.
issues code 2
@Component
public class ConsumerA {
@Reference(version = "1.0.0",retries = 0, timeout = 3000)
public ProviderB providerB ;
public void a(){
updateSomeRows(); //更新某行数据
try{
providerB.b();
}catch(Exception e){
throw new XXException();
}
}
}
@Service(version = "1.0.0")
public class ProviderB {
public void b(){
insertRow(); //插入某行数据
try{
Thread.sleep(10000); //休眠10秒为了模拟程序执行缓慢
}catch(Exception e){
}
}
}使用场景,当B服务提供者遇到数据库性能瓶颈(updateSomeRows()执行缓慢):
此时,A捕获超时异常,a()的事务因异常回滚,但是B的数据已插入,这是不符合预期的。请问怎么简单优雅地处理这样的问题(不考虑使用分布式事务的情况下)。
Usage scenario, when B service provider encounters a database performance bottleneck (execution of updateSomeRows() is slow):
At this point, A capture timeout exception, a () transaction rollback due to anomalies, but B's data has been inserted, which is not in line with expectations. How to handle such problems simply and gracefully (not considering the use of distributed transactions).
Activity
baigod commentedon Jun 25, 2018
#519
wanglei-sky commentedon Jun 29, 2018
顶
luyuanwan commentedon Jul 2, 2018
对于issue1,可以考虑使用dubbo的心跳,如果心跳检测不到,可以直接返回,不再等待。 @baigod
baigod commentedon Jul 3, 2018
@luyuanwan 具体怎么实现呢 : )
chickenlj commentedon Jul 10, 2018
For case 2, I am afraid there are no perfect solutions, when a heuristic exception occur, you can only retry or check offline.
For case 1, I think it's meaningful to notify the hanging client requests as soon as possible. When Server goes down it will trigger
disconnecton Client, and we can then return all requests related to this channel.carryxyh commentedon Aug 29, 2018
@baigod
Hi, I have fix the issue in case 1 by this pr:
#2185
For case 2, I agree with chickenlj.
U can keep it "eventually consistent".
Is there any other questions about this issue? If not, we will close it soon. :)
diecui1202 commentedon Sep 5, 2018
@carryxyh Does the PR #2185 need to merge back to 2.6.x?
carryxyh commentedon Sep 5, 2018
@diecui1202
Thanks for reminding me, I have not considered it before. I will submit a pr as soon as possible.
diecui1202 commentedon Sep 5, 2018
@carryxyh Great thanks.
diecui1202 commentedon Sep 6, 2018
#2451 has been merged to 2.6.x.
falcondsc commentedon Jul 29, 2019
@carryxyh 你好, 我們專案中(使用 2.5.3)也遇到 issues code 1 的困擾. 看到這個 issue (修正在2.6.4)之後. 我下載 2.6.6 的代碼到我本地運行. 但是發現. 我從 consumer 送出服務調用請求 並且進到 provider 之後,在 provider 返回處理結果前, 我手動把 provider 的進程刪除,我的 consumer 端仍然處於等待狀態. 為此我調試了 dubbo 2.6.6 底層代碼, 由於對 dubbo 的同訊架構不熟, 我只能從我調試的代碼看出, consumer 的確有收到 provider 斷開, 但是 consumer 收到通知的是 HeaderExchangeChannel 這個類, 而我看了git 上修正的 file, 關鍵的修正是在 HeaderExchangeHandler 類中的 disconnected 方法調用 DefaultFuture.closeChannel(channel);
因此我實驗性的修改了本地 HeaderExchangeChannel 的 close 方法 加入調用 DefaultFuture.closeChannel(channel); 重新打包後, 在我本地運行. 才真正解決了此 issue code 1 的問題. 請問我這樣修改是正確的嗎? 謝謝!
5 remaining items
falcondsc commentedon Jul 30, 2019
@beiwei30 你好. 請問一下你改的 master branch 是指主分支 2.7.x 嗎? 我測試是使用 2.6.6 的代碼進行修改的. 註冊中心使用的是 zookeeper. consumer 設定 timeout 為 10分鐘, 我並沒有對 2.7.x 版進行調整並測試這個問題.
本地目前在 2.6.6 調整完 HeaderExchangeChannel.close() 內先調用 DefaultFuture.closeChannel(channel); 或者選擇改 在 finally 才調用 DefaultFuture.closeChannel(channel); 都是可以在 consumer 送出請求後, 等到 provider 接入後, 刪除 provider 進程, consumer 都可以在幾秒內收到拋出的 "Channel xx is inactive. Directly return the unFinished request" 異常. 在未調整前. 我的 consumer 都是要等到 10 分鐘後才能得到一個 timeout exception.
接著 大概需要幾天的時間 我會先把自己改過的版本 放置我們 測試區 進行驗證. 隨後會再往前推進到我們的正式的生產環境.
(補充說明. 其實還有幾隻 dubbo 尋找 class loader 的代碼, 我是有特別修改為從當前線程取得 class loader , 但我認為不應該這幾隻修改, 會影響我本次測試的結果.)
以上的信息 希望對你有些幫助.
falcondsc commentedon Jul 30, 2019
補充一下: 另外我的 consumer retries 設定為 0
falcondsc commentedon Jul 30, 2019
我另外測試了 註冊中心是使用 Multicast 時. 那麼 consumer 的 HeaderExchangeChannel 將會是
public void close(int timeout) 這個方法被調用. 此場景下 consumer 也就只能繼續等待到 timeout 了.
beiwei30 commentedon Sep 5, 2019
@falcondsc 是的,是针对 master 分支做的分析和修复。2.6.x 上还麻烦你验证一下,如果工作的话,欢迎提 pull request 过来把 master 上的修复 backport 回来。
falcondsc commentedon Sep 9, 2019
@beiwei30
好的. 我會在本周三(9/11) 以前, 在 2.6.x 分支上 進行驗證.
falcondsc commentedon Sep 10, 2019
我獲取了 2.6.x 分支 在 HeaderExchangeChannel.close() 調用 DefaultFuture.closeChannel(channel); 方法. 但測試後發現調用到 HeaderExchangeChannel.close() 的堆棧 和 我先前用 2.6.6 去修改時有些不同, 2.6.x 分支代碼上慢了很多(關閉 dubbo provider 之後, 要等 30 秒以上)才會進到 consumer 端的HeaderExchangeChannel.close() .. 我先再繼續做些測試, 查看下是不是我兩個測試環境有不同而引起的問題.
falcondsc commentedon Sep 11, 2019
@beiwei30 想再請教一下, 因為剛接觸 github. 所以我反覆看了整個 issue 和關聯出去的內容.
你說的在 2.6.x 驗證. 是指包含 使用 你的 4700 pr 和 4698 pr 變更的內容 修改在我的 2.6.x repository上進行驗證嗎?
CrazyHZM commentedon Oct 10, 2021
Try it with the latest version, if you still have problems, you can reopen the issues