We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
/core/loadbalancer/randam.go下的Pick方法锁如下调整是不是更好: func (r *RandomStrategy) Pick() (*registry.MicroServiceInstance, error) { r.mtx.Lock() defer r.mtx.Unlock()
if len(r.instances) == 0 { return nil, ErrNoneAvailableInstance } k := rand.Int() % len(r.instances) return r.instances[k], nil
}
The text was updated successfully, but these errors were encountered:
感谢建议,请问目前的问题是什么
Sorry, something went wrong.
目前没有遇到问题,只是看到这段代码觉得并发情况下这样锁不安全,可能会遇到除0:
if len(r.instances) == 0 { return nil, ErrNoneAvailableInstance } r.mtx.Lock() k := rand.Int() % len(r.instances) r.mtx.Unlock() return r.instances[k], nil
tianxiaoliang
No branches or pull requests
/core/loadbalancer/randam.go下的Pick方法锁如下调整是不是更好:
func (r *RandomStrategy) Pick() (*registry.MicroServiceInstance, error) {
r.mtx.Lock()
defer r.mtx.Unlock()
}
The text was updated successfully, but these errors were encountered: