Use WaitGroup.Go

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2025-08-18 19:51:08 +02:00
parent 3276580fbd
commit c49d55b2a4
2 changed files with 8 additions and 17 deletions

View File

@@ -332,7 +332,6 @@ func (h *proxyHandler) allocPipe() (*os.File, *activePipe, error) {
w: pipew,
}
h.activePipes[uint32(pipew.Fd())] = &f
f.wg.Add(1)
return piper, &f, nil
}
@@ -345,14 +344,12 @@ func (h *proxyHandler) returnBytes(retval any, buf []byte) (replyBuf, error) {
return ret, err
}
go func() {
// Signal completion when we return
defer f.wg.Done()
f.wg.Go(func() {
_, err = io.Copy(f.w, bytes.NewReader(buf))
if err != nil {
f.err = err
}
}()
})
ret.value = retval
ret.fd = piper
@@ -583,10 +580,8 @@ func (h *proxyHandler) GetBlob(args []any) (replyBuf, error) {
blobr.Close()
return ret, err
}
go func() {
// Signal completion when we return
f.wg.Go(func() {
defer blobr.Close()
defer f.wg.Done()
verifier := d.Verifier()
tr := io.TeeReader(blobr, verifier)
n, err := io.Copy(f.w, tr)
@@ -600,7 +595,7 @@ func (h *proxyHandler) GetBlob(args []any) (replyBuf, error) {
if !verifier.Verified() {
f.err = fmt.Errorf("corrupted blob, expecting %s", d.String())
}
}()
})
ret.value = blobSize
ret.fd = piper

View File

@@ -214,9 +214,7 @@ func (p *proxy) callGetRawBlob(args []any) (rval any, buf []byte, err error) {
var wg sync.WaitGroup
fetchchan := make(chan byteFetch, 1)
errchan := make(chan proxyError, 1)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
defer close(fetchchan)
defer fd.datafd.Close()
buf, err := io.ReadAll(fd.datafd)
@@ -224,10 +222,8 @@ func (p *proxy) callGetRawBlob(args []any) (rval any, buf []byte, err error) {
content: buf,
err: err,
}
}()
wg.Add(1)
go func() {
defer wg.Done()
})
wg.Go(func() {
defer fd.errfd.Close()
defer close(errchan)
buf, err := io.ReadAll(fd.errfd)
@@ -248,7 +244,7 @@ func (p *proxy) callGetRawBlob(args []any) (rval any, buf []byte, err error) {
panic(unmarshalErr)
}
errchan <- proxyErr
}()
})
wg.Wait()
errMsg := <-errchan