Skip to content

Commit

Permalink
[server] fix multi grpc request may cause panic
Browse files Browse the repository at this point in the history
  • Loading branch information
lzf575 authored and sharang committed Sep 24, 2023
1 parent 3abee07 commit bc622aa
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions server/libs/grpc/grpc_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ func (s *GrpcSession) SetSyncInterval(syncInterval time.Duration) {

func (s *GrpcSession) nextServer() error {
s.CloseConnection()
s.ipIndex++
if s.ipIndex >= len(s.ips) {
// fix where multi thread run, may cause s.ipIndex++ >= s.ips and cause panic
ipIndex := s.ipIndex + 1
if ipIndex >= len(s.ips) {
s.ipIndex = 0
ipIndex = 0
} else {
s.ipIndex = ipIndex
}
server := fmt.Sprintf("%s:%d", s.ips[s.ipIndex], s.port)
if s.ips[s.ipIndex].To4() == nil {
server = fmt.Sprintf("[%s]:%d", s.ips[s.ipIndex], s.port)
server := fmt.Sprintf("%s:%d", s.ips[ipIndex], s.port)
if s.ips[ipIndex].To4() == nil {
server = fmt.Sprintf("[%s]:%d", s.ips[ipIndex], s.port)
}
options := make([]grpc.DialOption, 0, 4)
options = append(options, grpc.WithInsecure(), grpc.WithTimeout(s.syncInterval),
Expand Down

0 comments on commit bc622aa

Please sign in to comment.