From a0d027abded467201254ad429e4a9725dad6219e Mon Sep 17 00:00:00 2001 From: Elijah Zupancic Date: Thu, 8 Jun 2023 03:12:20 -0700 Subject: [PATCH] fix: fixes segfault when process is TERMed (#335) Fixes #334 This change prevents agent from having a segmentation fault when it receives a TERM or INT signal. --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b218c4899..7ab4fbfb3 100644 --- a/main.go +++ b/main.go @@ -130,7 +130,9 @@ func handleSignals( ) log.Debugf("Sending agent stopped event: %v", stopCmd) - if err := cmder.Send(ctx, client.MessageFromCommand(stopCmd)); err != nil { + if cmder == nil { + log.Warn("Command channel not configured. Skipping sending AgentStopped event") + } else if err := cmder.Send(ctx, client.MessageFromCommand(stopCmd)); err != nil { log.Errorf("Error sending AgentStopped event to command channel: %v", err) }