From 078a6c5e9e6e9e6e1037da6dcf953623e7d38500 Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Thu, 3 Aug 2023 17:28:37 -0400 Subject: [PATCH] fix: some hang conditions (#1414) Signed-off-by: Keith Zantow --- cmd/grype/internal/ui/ui.go | 7 +++++-- grype/pkg/syft_provider.go | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/grype/internal/ui/ui.go b/cmd/grype/internal/ui/ui.go index 5814e8033a4..0e2056a2d91 100644 --- a/cmd/grype/internal/ui/ui.go +++ b/cmd/grype/internal/ui/ui.go @@ -82,12 +82,15 @@ func (m *UI) Teardown(force bool) error { if !force { m.handler.Wait() m.program.Quit() + // typically in all cases we would want to wait for the UI to finish. However there are still error cases + // that are not accounted for, resulting in hangs. For now, we'll just wait for the UI to finish in the + // happy path only. There will always be an indication of the problem to the user via reporting the error + // string from the worker (outside of the UI after teardown). + m.running.Wait() } else { m.program.Kill() } - m.running.Wait() - // TODO: allow for writing out the full log output to the screen (only a partial log is shown currently) // this needs coordination to know what the last frame event is to change the state accordingly (which isn't possible now) diff --git a/grype/pkg/syft_provider.go b/grype/pkg/syft_provider.go index 8094f9794b5..6aa7d96cd4d 100644 --- a/grype/pkg/syft_provider.go +++ b/grype/pkg/syft_provider.go @@ -1,6 +1,7 @@ package pkg import ( + "github.com/anchore/grype/internal/log" "github.com/anchore/stereoscope/pkg/image" "github.com/anchore/syft/syft" "github.com/anchore/syft/syft/sbom" @@ -13,7 +14,13 @@ func syftProvider(userInput string, config ProviderConfig) ([]Package, Context, return nil, Context{}, nil, err } - defer src.Close() + defer func() { + if src != nil { + if err := src.Close(); err != nil { + log.Tracef("unable to close source: %+v", err) + } + } + }() catalog, relationships, theDistro, err := syft.CatalogPackages(src, config.CatalogingOptions) if err != nil {