Skip to content

Commit 801c330

Browse files
committed
estargz: Build: replace golang.org/x/sync with WaitGroup.Go (go1.25)
It was only using minimal functionality of the errgroup (and didn't use, e.g. `errgroup.WithContext`). Rewrite it with a sync.WaitGroup from stdlib. Also update to go1.25 and use WaitGroup.Go Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 7173f0e commit 801c330

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

estargz/build.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/containerd/stargz-snapshotter/estargz/errorutil"
4141
"github.com/klauspost/compress/zstd"
4242
digest "github.com/opencontainers/go-digest"
43-
"golang.org/x/sync/errgroup"
4443
)
4544

4645
type GzipHelperFunc func(io.Reader) (io.ReadCloser, error)
@@ -235,14 +234,16 @@ func Build(tarBlob *io.SectionReader, opt ...Option) (_ *Blob, rErr error) {
235234
}
236235
writers := make([]*Writer, len(tarParts))
237236
payloads := make([]*os.File, len(tarParts))
238-
var eg errgroup.Group
237+
var wg sync.WaitGroup
238+
errCh := make(chan error, len(tarParts)) // buffered to avoid goroutine leaks
239239
for i, parts := range tarParts {
240240
i, parts := i, parts
241241
// builds verifiable stargz sub-blobs
242-
eg.Go(func() error {
242+
wg.Go(func() {
243243
esgzFile, err := layerFiles.TempFile("", "esgzdata")
244244
if err != nil {
245-
return err
245+
errCh <- err
246+
return
246247
}
247248
sw := NewWriterWithCompressor(esgzFile, opts.compression)
248249
sw.ChunkSize = opts.chunkSize
@@ -254,16 +255,20 @@ func Build(tarBlob *io.SectionReader, opt ...Option) (_ *Blob, rErr error) {
254255
sw.needsOpenGzEntries[f] = struct{}{}
255256
}
256257
if err := sw.AppendTar(readerFromEntries(parts...)); err != nil {
257-
return err
258+
errCh <- err
259+
return
258260
}
259261
writers[i] = sw
260262
payloads[i] = esgzFile
261-
return nil
262263
})
263264
}
264-
if err := eg.Wait(); err != nil {
265-
rErr = err
266-
return nil, err
265+
wg.Wait()
266+
close(errCh)
267+
268+
for err := range errCh {
269+
if err != nil {
270+
return nil, err
271+
}
267272
}
268273
tocAndFooter, tocDgst, err := closeWithCombine(writers...)
269274
if err != nil {

estargz/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module github.com/containerd/stargz-snapshotter/estargz
22

3-
go 1.24.0
3+
go 1.25.0
44

55
require (
66
github.com/klauspost/compress v1.18.3
77
github.com/opencontainers/go-digest v1.0.0
88
github.com/vbatts/tar-split v0.12.2
9-
golang.org/x/sync v0.19.0
109
)

estargz/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
44
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
55
github.com/vbatts/tar-split v0.12.2 h1:w/Y6tjxpeiFMR47yzZPlPj/FcPLpXbTUi/9H7d3CPa4=
66
github.com/vbatts/tar-split v0.12.2/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA=
7-
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
8-
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=

0 commit comments

Comments
 (0)