From 87846cbbf05d84f9b699c9a848a8ec1b539f06fd Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 14 Nov 2024 12:26:33 -0500 Subject: [PATCH] Pass errors up the stack in CalculateWorld and InstallPackages (#1404) Make sure to close channel in InstallPackages, cleanup in CalculateWorld This problem was found in melange https://github.com/chainguard-dev/melange/issues/1645 Any time a download failed, we would hang waiting for a close that would never occur. Signed-off-by: Scott Moser --- pkg/apk/apk/implementation.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/apk/apk/implementation.go b/pkg/apk/apk/implementation.go index 34d52b94..34537d14 100644 --- a/pkg/apk/apk/implementation.go +++ b/pkg/apk/apk/implementation.go @@ -523,14 +523,7 @@ func (a *APK) CalculateWorld(ctx context.Context, allpkgs []*RepositoryPackage) resolved := make([]*APKResolved, len(allpkgs)) - // A slice of pseudo-promises that get closed when expanded[i] is ready. - done := make([]chan struct{}, len(allpkgs)) - for i := range allpkgs { - done[i] = make(chan struct{}) - } - - // Meanwhile, concurrently fetch and expand all our APKs. - // We signal they are ready to be installed by closing done[i]. + // concurrently fetch and expand all our APKs. for i, pkg := range allpkgs { i, pkg := i, pkg @@ -547,8 +540,6 @@ func (a *APK) CalculateWorld(ctx context.Context, allpkgs []*RepositoryPackage) res.Package = pkg resolved[i] = res - close(done[i]) - return nil }) } @@ -664,6 +655,10 @@ func (a *APK) InstallPackages(ctx context.Context, sourceDateEpoch *time.Time, a exp := expanded[i] pkg := allpkgs[i] + if exp == nil { + return fmt.Errorf("expansion of %s failed", pkg) + } + isInstalled, err := a.isInstalledPackage(pkg.PackageName()) if err != nil { return fmt.Errorf("error checking if package %s is installed: %w", pkg, err) @@ -698,13 +693,13 @@ func (a *APK) InstallPackages(ctx context.Context, sourceDateEpoch *time.Time, a i, pkg := i, pkg g.Go(func() error { + defer func() { close(done[i]) }() exp, err := a.expandPackage(ctx, pkg) if err != nil { return fmt.Errorf("expanding %s: %w", pkg, err) } expanded[i] = exp - close(done[i]) return nil })