Skip to content

Commit 3294c68

Browse files
committed
uploadprovider: allow closing used sources
Helps detecting when uploadprovider has finished with the source. This avoids deadlock, should the same reader be shared by multiple uploads that sync with each other. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 5e729c3 commit 3294c68

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5256,7 +5256,7 @@ COPY foo /
52565256
defer c.Close()
52575257

52585258
up := uploadprovider.New()
5259-
url := up.Add(buf)
5259+
url := up.Add(io.NopCloser(buf))
52605260

52615261
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
52625262
FrontendAttrs: map[string]string{
@@ -5301,7 +5301,7 @@ COPY foo bar
53015301
defer c.Close()
53025302

53035303
up := uploadprovider.New()
5304-
url := up.Add(buf)
5304+
url := up.Add(io.NopCloser(buf))
53055305

53065306
// repeat with changed default args should match the old cache
53075307
destDir := t.TempDir()

session/upload/uploadprovider/provider.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
)
1414

1515
func New() *Uploader {
16-
return &Uploader{m: map[string]io.Reader{}}
16+
return &Uploader{m: map[string]io.ReadCloser{}}
1717
}
1818

1919
type Uploader struct {
2020
mu sync.Mutex
21-
m map[string]io.Reader
21+
m map[string]io.ReadCloser
2222
}
2323

24-
func (hp *Uploader) Add(r io.Reader) string {
24+
func (hp *Uploader) Add(r io.ReadCloser) string {
2525
id := identity.NewID()
2626
hp.m[id] = r
2727
return "http://buildkit-session/" + id
@@ -51,6 +51,11 @@ func (hp *Uploader) Pull(stream upload.Upload_PullServer) error {
5151
hp.mu.Unlock()
5252

5353
_, err := io.Copy(&writer{stream}, r)
54+
55+
if err1 := r.Close(); err == nil {
56+
err = err1
57+
}
58+
5459
return err
5560
}
5661

0 commit comments

Comments
 (0)