Skip to content

Commit

Permalink
Fix resource usage in melange
Browse files Browse the repository at this point in the history
Apparently `for { select { break } }` doesn't do what I thought.

This cleans up orphaned goroutines after the reader is done.

Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
  • Loading branch information
jonjohnsonjr committed Feb 29, 2024
1 parent 4678d38 commit 67f2fe9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/contextreader/contextreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *contextReader) init() {
c.n, c.err = c.r.Read(p)
c.done <- struct{}{}
case <-c.ctx.Done():
break
return
}
}
}()
Expand Down
2 changes: 2 additions & 0 deletions pkg/container/docker/docker_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func (dk *docker) waitForCommand(ctx context.Context, r io.Reader) error {
defer stderr.Close()

// Wrap this in a contextReader so we respond to cancel.
ctx, cancel := context.WithCancel(ctx)
defer cancel()
ctxr := contextreader.New(ctx, r)

_, err := stdcopy.StdCopy(stdout, stderr, ctxr)
Expand Down

0 comments on commit 67f2fe9

Please sign in to comment.