From aec39c9194ca808630de704a95782633b06e1500 Mon Sep 17 00:00:00 2001 From: Nandor Magyar Date: Fri, 19 Apr 2024 17:11:46 +0200 Subject: [PATCH] fix: fix agent grpc connection hanging --- golang/internal/grpc/grpc.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/golang/internal/grpc/grpc.go b/golang/internal/grpc/grpc.go index 085cdb315..89ff2dd33 100644 --- a/golang/internal/grpc/grpc.go +++ b/golang/internal/grpc/grpc.go @@ -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) }