Skip to content
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

Possible division by zero #7763

Closed
Bbulatov opened this issue Oct 21, 2024 · 1 comment
Closed

Possible division by zero #7763

Bbulatov opened this issue Oct 21, 2024 · 1 comment
Assignees
Labels
Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. Type: Bug

Comments

@Bbulatov
Copy link

Hello!
During the static analysis was found possible mistake:

  1. Variable subConnsLen, whose possible value set allows a zero value at roundrobin.go:76, is used as a denominator at roundrobin.go:79.
func (p *rrPicker) Pick(balancer.PickInfo) (balancer.PickResult, error) {
	subConnsLen := uint32(len(p.subConns))
	nextIndex := atomic.AddUint32(&p.next, 1)

	sc := p.subConns[nextIndex%subConnsLen]
	return balancer.PickResult{SubConn: sc}, nil
}

version of gRPC: master
version of Go: go version go1.22.4 linux/amd64
operating system: Linux debian 10

@aranjans aranjans self-assigned this Oct 21, 2024
@aranjans
Copy link
Contributor

@Bbulatov This case is already handled by base balancer here and hence we won't need to have this condition in roundrobin explicitly.

@purnesh42H purnesh42H added the Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants