Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass errors up the stack in CalculateWorld and InstallPackages #1404

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

smoser
Copy link
Contributor

@smoser smoser commented Nov 14, 2024

Make sure to close channel in InstallPackages, cleanup in CalculateWorld

This problem was found in melange chainguard-dev/melange#1645

Any time a download failed, we would hang waiting for a close
that would never occur.

@smoser smoser force-pushed the fix/catch-failed-downloadds branch 3 times, most recently from a5bbb7f to d5d4236 Compare November 14, 2024 16:13
@luhring
Copy link
Member

luhring commented Nov 14, 2024

@jonjohnsonjr This looks up your alley 👀

@@ -524,9 +524,9 @@ 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))
done := make([]chan error, len(allpkgs))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually just delete these because there's nothing that reads from these channels. I think this was a copy-paste leftover.

@@ -700,13 +707,13 @@ func (a *APK) InstallPackages(ctx context.Context, sourceDateEpoch *time.Time, a
g.Go(func() error {
exp, err := a.expandPackage(ctx, pkg)
if err != nil {
return fmt.Errorf("expanding %s: %w", pkg, err)
err = fmt.Errorf("expanding %s: %w", pkg, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do something like:

g.Go(func() (rerr error) {
  defer func() { done[i] <- rerr }()

  exp, err := a.expandPackage(ctx, pkg)
  if err != nil {
    return fmt.Errorf("expanding %s: %w", pkg, err)
  }

  expanded[i] = exp

  return nil
})

That creates a named return (yucky but useful for this error handling stuff) and closes done[i] with the returned error (which is nil on success).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not love this approach actually because now we need buffered channels instead of unbuffered if we're going to send 🤔

This problem was found in melange
 chainguard-dev/melange#1645

Any time a download failed, we would hang waiting for a close
that would never occur.

Signed-off-by: Scott Moser <[email protected]>
@smoser smoser force-pushed the fix/catch-failed-downloadds branch from d5d4236 to 3d2aa38 Compare November 14, 2024 17:21
@smoser smoser merged commit 87846cb into chainguard-dev:main Nov 14, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants