context: fix errgroup interaction with context

Fixes #3307
This commit is contained in:
Aleksandar Jankovic
2019-07-01 10:33:21 +02:00
committed by Nick Craig-Wood
parent af2596f98b
commit 7b2b396d37
2 changed files with 9 additions and 9 deletions

View File

@@ -122,9 +122,9 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object,
return nil, errors.New("multi-thread copy: can't copy zero sized file")
}
g, ctx := errgroup.WithContext(context.Background())
g, gCtx := errgroup.WithContext(ctx)
mc := &multiThreadCopyState{
ctx: ctx,
ctx: gCtx,
size: src.Size(),
src: src,
streams: streams,
@@ -136,7 +136,7 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object,
defer fs.CheckClose(mc.acc, &err)
// create write file handle
mc.wc, err = openWriterAt(ctx, remote, mc.size)
mc.wc, err = openWriterAt(gCtx, remote, mc.size)
if err != nil {
return nil, errors.Wrap(err, "multpart copy: failed to open destination")
}
@@ -146,7 +146,7 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object,
for stream := 0; stream < mc.streams; stream++ {
stream := stream
g.Go(func() (err error) {
return mc.copyStream(ctx, stream)
return mc.copyStream(gCtx, stream)
})
}
err = g.Wait()