travisjeffery / proglog

grpc log service example project
187 stars 76 forks source link

error: integer divide by zero in picker nextFollower method #10

Closed akolybelnikov closed 2 years ago

akolybelnikov commented 2 years ago

If len(p.followers) == 0 in Pick it attempts to assign a next follower to the result.SubConn, but the nextFollower throws an integer divide by zero runtime error because in Go % 0 is division by zero. The error is detectable if you run TestPickerNoSubConnAvailable.

I am checking for the length and returning nil early, but checking if strings.Contains(info.FullMethodName, "Produce") || len(p.followers) == 0 loses its meaning in Pick.

akolybelnikov commented 2 years ago

The actual method includes the following:


if​ strings.Contains(info.FullMethodName, ​"Produce"​) || len(p.followers) == 0 {
    result.SubConn = p.leader
} ​else​ ​if​ strings.Contains(info.FullMethodName, ​"Consume"​) {
    result.SubConn = p.nextFollower()
​}

I have entirely missed the else-if statement. I need to chill...