HGD-coder commented on PR #3184: URL: https://github.com/apache/dubbo-go/pull/3184#issuecomment-3815432229
<img width="1046" height="1050" alt="image" src="https://github.com/user-attachments/assets/c4230590-556c-4b57-8e71-57e1005d7e7a" /> <img width="758" height="637" alt="image" src="https://github.com/user-attachments/assets/ebfaf67b-6c81-4537-b481-316c190e3030" /> > 我觉得这个方法还是太不优雅了,因为上游对于url为nil时候的处理是不一样的,简单粗暴的返回一个空链接我个人觉得不好 > > 只在发生panic的那个上游加一个对于nil的检测可以吗,GetURL这个函数这样改 1.太多地方用到GetURL()了,它们都是在Destory()增加url=nil前写的。只修改部分未来是否还有风险? 2.这一次panic是一个调用链中多处偶发(protocol/base/rpc_status.go内的invoker.GetURL().Key()和cluster/router/chain/chain.go的invoker.GetURL().ServiceKey()等),一路上用到的GetURL有点多,并不是修改一个上游,我之前尝试过增加url判空。但是碰到下面这种代码,或者说其他我本来就不清楚机制的代码,并不是加一层过滤就能解决,我自己擅自修改,可能引入其他的bug,我感觉改的越多,错的概率越大。 ``` cluster/router/chain/chain.go // Route Loop routers in RouterChain and call Route method to determine the target invokers list. func (c *RouterChain) Route(url *common.URL, invocation base.Invocation) []base.Invoker { finalInvokers := make([]base.Invoker, 0, len(c.invokers)) // multiple invoker may include different methods, find correct invoker otherwise // will return the invoker without methods for _, invoker := range c.invokers { //假设在这里加了url判空 if invoker.GetURL().ServiceKey() == url.ServiceKey() { finalInvokers = append(finalInvokers, invoker) } } // 【危险】因为上面没选出人来,系统决定“死马当活马医” // 强制把原始列表(包含那个url==nil的invoker)赋值回来 if len(finalInvokers) == 0 { finalInvokers = c.invokers } for _, r := range c.copyRouters() { finalInvokers = r.Route(finalInvokers, url, invocation) } return finalInvokers } ``` -- 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]
