AlexStocks commented on code in PR #892:
URL: https://github.com/apache/dubbo-go-pixiu/pull/892#discussion_r3032490352
##########
pkg/common/router/router.go:
##########
@@ -65,7 +75,23 @@ func CreateRouterCoordinator(routeConfig
*model.RouteConfiguration) *RouterCoord
return rc
}
+func (rm *RouterCoordinator) Close() {
+ if rm.dynamic {
+ routerMgr := server.GetRouterManager()
+ if routerMgr != nil {
+ routerMgr.RemoveRouterListener(rm)
+ }
+ }
+}
+
func (rm *RouterCoordinator) Route(hc *http.HttpContext) (*model.RouteAction,
error) {
+ if rm.needsRegistration.Load() && rm.dynamic {
+ routerMgr := server.GetRouterManager()
+ if routerMgr != nil {
+ routerMgr.AddRouterListener(rm)
Review Comment:
[P1] 这里把 `needsRegistration` 从普通布尔值改成了 `atomic.Bool`,原来的 data race
确实没有了,但当前实现仍然不是一次性注册:两个并发请求都可能在 `Load()` 时看到 `true`,随后各自执行
`AddRouterListener(rm)`,最后都再 `Store(false)`。`RouterManager` 本身没有去重,这会把同一个
coordinator 注册多次,后续热更新时同一条路由会被重复追加到 `nextSnapshot`。这里需要把“检查并清空标记”做成原子操作,比如用
`CompareAndSwap(true, false)` 或 `sync.Once` 包住注册路径。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]