From 3eecd06aca6c8ddf9cee5f75fea6f452ecfaabb0 Mon Sep 17 00:00:00 2001 From: Salim Afiune Maya Date: Fri, 27 Dec 2024 13:50:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20recover=20from=20panic's=20insid?= =?UTF-8?q?e=20goroutines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main cnspec goroutine has already a `recover()` statement, though Go doesn't share that between goroutines and since the calculation of the policies happen on another thread, we were not reporting upstream. Signed-off-by: Salim Afiune Maya --- policy/executor/internal/collector.go | 3 +++ policy/executor/internal/execution_manager.go | 3 +++ policy/scan/local_scanner.go | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/policy/executor/internal/collector.go b/policy/executor/internal/collector.go index 3067bf97..66f2ac6a 100644 --- a/policy/executor/internal/collector.go +++ b/policy/executor/internal/collector.go @@ -11,7 +11,9 @@ import ( "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v11/llx" + "go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream/health" "go.mondoo.com/cnquery/v11/utils/iox" + "go.mondoo.com/cnspec/v11" "go.mondoo.com/cnspec/v11/policy" "google.golang.org/protobuf/proto" ) @@ -122,6 +124,7 @@ func (c *BufferedCollector) run() { c.wg.Add(1) go func() { defer c.wg.Done() + defer health.ReportPanic("cnspec", cnspec.Version, cnspec.Build) done := false results := []*llx.RawResult{} diff --git a/policy/executor/internal/execution_manager.go b/policy/executor/internal/execution_manager.go index 26a4b2b9..7deab739 100644 --- a/policy/executor/internal/execution_manager.go +++ b/policy/executor/internal/execution_manager.go @@ -12,6 +12,8 @@ import ( "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v11/llx" + "go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream/health" + "go.mondoo.com/cnspec/v11" ) const MEM_DEBUG_ENV = "MEM_DEBUG" @@ -63,6 +65,7 @@ func (em *executionManager) Start() { em.wg.Add(1) go func() { defer em.wg.Done() + defer health.ReportPanic("cnspec", cnspec.Version, cnspec.Build) for { // Prioritize stopChan select { diff --git a/policy/scan/local_scanner.go b/policy/scan/local_scanner.go index 1a66341a..f63797a8 100644 --- a/policy/scan/local_scanner.go +++ b/policy/scan/local_scanner.go @@ -30,6 +30,7 @@ import ( "go.mondoo.com/cnquery/v11/providers-sdk/v1/recording" "go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream" "go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream/gql" + "go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream/health" "go.mondoo.com/cnquery/v11/utils/multierr" "go.mondoo.com/cnquery/v11/utils/slicesx" "go.mondoo.com/cnspec/v11" @@ -314,6 +315,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up scanGroups.Add(1) go func() { defer scanGroups.Done() + defer health.ReportPanic("cnspec", cnspec.Version, cnspec.Build) + if err := multiprogress.Open(); err != nil { log.Error().Err(err).Msg("failed to open progress bar") } @@ -415,6 +418,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up wg.Add(1) go func() { defer wg.Done() + defer health.ReportPanic("cnspec", cnspec.Version, cnspec.Build) + for i := range batch { asset := batch[i].Asset runtime := batch[i].Runtime