Skip to content

Commit

Permalink
fix: fix agent grpc connection hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
nandor-magyar committed Apr 19, 2024
1 parent 60ca730 commit aec39c9
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions golang/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,19 @@ func initWithToken(
log.Info().Str("address", address).Msg("Dialing to address.")
conn, err := grpc.NewClient(address, opts...)
if err != nil {
log.Panic().Stack().Err(err).Msg("Failed to dial gRPC")
return err
}

for {
state := conn.GetState()
if state != connectivity.Ready {
log.Debug().Msgf("Waiting for state to change: %d", state)
conn.WaitForStateChange(loop.Ctx, state)
log.Debug().Msgf("State Changed to: %d", conn.GetState())
} else {
if state == connectivity.Ready || state == connectivity.Idle {
break
}
}
if err != nil {
log.Error().Stack().Err(err).Msg("gRPC connection error")
log.Debug().Msgf("Waiting for state to change: %s", state.String())
conn.WaitForStateChange(loop.Ctx, state)
log.Debug().Msgf("State Changed to: %d", conn.GetState())
}
grpcConn.Conn = conn

return loop.grpcLoop(token)
}

Expand Down

0 comments on commit aec39c9

Please sign in to comment.