-
Notifications
You must be signed in to change notification settings - Fork 131
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
Pass errors up the stack in CalculateWorld and InstallPackages #1404
Conversation
a5bbb7f
to
d5d4236
Compare
@jonjohnsonjr This looks up your alley 👀 |
pkg/apk/apk/implementation.go
Outdated
@@ -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)) |
There was a problem hiding this comment.
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.
pkg/apk/apk/implementation.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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]>
d5d4236
to
3d2aa38
Compare
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.