-
Notifications
You must be signed in to change notification settings - Fork 339
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 listener receiving encrypted content when kms is open. #549
Conversation
@@ -481,7 +481,14 @@ func (client *ConfigClient) refreshContentAndCheck(cacheData *cacheData, notify | |||
} | |||
cacheData.md5 = util.Md5(cacheData.content) | |||
if cacheData.md5 != cacheData.cacheDataListener.lastMd5 { | |||
go cacheData.cacheDataListener.listener(cacheData.tenant, cacheData.group, cacheData.dataId, cacheData.content) | |||
var decryptedContent string | |||
decryptedContent, err = client.decrypt(cacheData.dataId, cacheData.content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decryptedContent, err := client.decrypt(cacheData.dataId, cacheData.content) 使用:=简洁一些
cacheData.group, cacheData.tenant) | ||
return | ||
} | ||
go cacheData.cacheDataListener.listener(cacheData.tenant, cacheData.group, cacheData.dataId, decryptedContent) | ||
cacheData.cacheDataListener.lastMd5 = cacheData.md5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将设置md5以及更新cacheMap的逻辑 放到decrypt和回调listenr前,当解密出现err时 也可以正常的更新md5。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache逻辑必须放在decrypt()之后,不然decrypt() 异常不会重新触发listener。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目的就是异常后不重新出发listenr,打印日志就可以了。 因为一旦发生异常大概率会造成重复触发listener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更新md5也放在回调listener前
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我认为cacheDataListener.lastMd5的更新应该放在decrypt()之后,用来判断是否触发listener,你怎么看?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和上面的逻辑是一样的,如果不更新md5会重复触发listener。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按我理解,只有用户开启加密且以下场景之一,才会导致解密失败:
- 网络导致
- 数据错误
对于 1,应该重复触发listener;对于2,不能重复触发。
我们无法区分1、2,所以统一不重复触发listener。
我理解对吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,相当于降级处理。某一次的decrypt失败,不会使sdk一直循环在notify的逻辑,否则不仅仅是sdk的服务CPU上升,还会增大nacos server的压力。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
Codecov ReportBase: 29.99% // Head: 31.26% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #549 +/- ##
==========================================
+ Coverage 29.99% 31.26% +1.27%
==========================================
Files 40 40
Lines 2967 2987 +20
==========================================
+ Hits 890 934 +44
+ Misses 2013 1988 -25
- Partials 64 65 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
fixes:#507