From bbde6ac55470cf05c6444adeda3845a03adc1725 Mon Sep 17 00:00:00 2001 From: Daniel Dias Date: Mon, 9 Sep 2024 16:48:37 -0300 Subject: [PATCH] fix(agent): update error handling on shutdown --- agent/runner/runstrategy_verbose.go | 10 +++++----- agent/runner/session.go | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/agent/runner/runstrategy_verbose.go b/agent/runner/runstrategy_verbose.go index f684f7242e..49cfaecec8 100644 --- a/agent/runner/runstrategy_verbose.go +++ b/agent/runner/runstrategy_verbose.go @@ -18,11 +18,11 @@ func (s *Runner) RunVerboseStrategy(ctx context.Context, cfg agentConfig.Config) s.ui.Infof("%s Starting Agent with name %s...", consoleUI.Emoji_Truck, cfg.Name) session, err := StartSession(ctx, cfg, &verboseObserver{ui: s.ui}, s.logger) - - if err != nil && errors.Is(err, ErrOtlpServerStart) { - s.ui.Errorf("%s Tracetest Agent binds to the OpenTelemetry ports 4317 and 4318 which are used to receive trace information from your system. The agent tried to bind to these ports, but failed.", consoleUI.Emoji_RedCircle) - - s.ui.Finish() + if err != nil { + if errors.Is(err, ErrOtlpServerStart) { + s.ui.Errorf("%s Tracetest Agent binds to the OpenTelemetry ports 4317 and 4318 which are used to receive trace information from your system. The agent tried to bind to these ports, but failed.", consoleUI.Emoji_RedCircle) + s.ui.Finish() + } return err } diff --git a/agent/runner/session.go b/agent/runner/session.go index a1e4a03af7..8650301652 100644 --- a/agent/runner/session.go +++ b/agent/runner/session.go @@ -28,7 +28,9 @@ type Session struct { } func (s *Session) Close() { - s.client.Close() + if s != nil && s.client != nil { + s.client.Close() + } } func (s *Session) WaitUntilDisconnected() {