mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 14:17:42 +00:00
Merge pull request #3204 from MichaelEischer/archiver-tomb-race
archiver: fix race condition during worker startup
This commit is contained in:
commit
8b84c96d9d
@ -784,33 +784,31 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
|
|||||||
|
|
||||||
var t tomb.Tomb
|
var t tomb.Tomb
|
||||||
wctx := t.Context(ctx)
|
wctx := t.Context(ctx)
|
||||||
|
|
||||||
arch.runWorkers(wctx, &t)
|
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
debug.Log("starting snapshot")
|
var rootTreeID restic.ID
|
||||||
rootTreeID, stats, err := func() (restic.ID, ItemStats, error) {
|
var stats ItemStats
|
||||||
|
t.Go(func() error {
|
||||||
|
arch.runWorkers(wctx, &t)
|
||||||
|
|
||||||
|
debug.Log("starting snapshot")
|
||||||
tree, err := arch.SaveTree(wctx, "/", atree, arch.loadParentTree(wctx, opts.ParentSnapshot))
|
tree, err := arch.SaveTree(wctx, "/", atree, arch.loadParentTree(wctx, opts.ParentSnapshot))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return restic.ID{}, ItemStats{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tree.Nodes) == 0 {
|
if len(tree.Nodes) == 0 {
|
||||||
return restic.ID{}, ItemStats{}, errors.New("snapshot is empty")
|
return errors.New("snapshot is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
return arch.saveTree(wctx, tree)
|
rootTreeID, stats, err = arch.saveTree(wctx, tree)
|
||||||
}()
|
// trigger shutdown but don't set an error
|
||||||
debug.Log("saved tree, error: %v", err)
|
t.Kill(nil)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
t.Kill(nil)
|
err = t.Wait()
|
||||||
werr := t.Wait()
|
debug.Log("err is %v", err)
|
||||||
debug.Log("err is %v, werr is %v", err, werr)
|
|
||||||
// Use werr when it might contain a more specific error than "context canceled"
|
|
||||||
if err == nil || (errors.Cause(err) == context.Canceled && werr != nil) {
|
|
||||||
err = werr
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("error while saving tree: %v", err)
|
debug.Log("error while saving tree: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user