Skip to content

Commit 376ae59

Browse files
authored
Merge pull request #2249 from thaJeztah/no_sync
estargz: Build: replace golang.org/x/sync with WaitGroup.Go (go1.25)
2 parents 0b9f220 + 801c330 commit 376ae59

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

estargz/build.go

Lines changed: 14 additions & 12 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,15 @@ 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 mu sync.Mutex
239-
var eg errgroup.Group
237+
var wg sync.WaitGroup
238+
errCh := make(chan error, len(tarParts)) // buffered to avoid goroutine leaks
240239
for i, parts := range tarParts {
241240
// builds verifiable stargz sub-blobs
242-
eg.Go(func() error {
241+
wg.Go(func() {
243242
esgzFile, err := layerFiles.TempFile("", "esgzdata")
244243
if err != nil {
245-
return err
244+
errCh <- err
245+
return
246246
}
247247
sw := NewWriterWithCompressor(esgzFile, opts.compression)
248248
sw.ChunkSize = opts.chunkSize
@@ -254,18 +254,20 @@ func Build(tarBlob *io.SectionReader, opt ...Option) (_ *Blob, rErr error) {
254254
sw.needsOpenGzEntries[f] = struct{}{}
255255
}
256256
if err := sw.AppendTar(readerFromEntries(parts...)); err != nil {
257-
return err
257+
errCh <- err
258+
return
258259
}
259-
mu.Lock()
260260
writers[i] = sw
261261
payloads[i] = esgzFile
262-
mu.Unlock()
263-
return nil
264262
})
265263
}
266-
if err := eg.Wait(); err != nil {
267-
rErr = err
268-
return nil, err
264+
wg.Wait()
265+
close(errCh)
266+
267+
for err := range errCh {
268+
if err != nil {
269+
return nil, err
270+
}
269271
}
270272
tocAndFooter, tocDgst, err := closeWithCombine(writers...)
271273
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)