diff --git a/fs/filter/filter.go b/fs/filter/filter.go index 156dbd4a7..736495f4d 100644 --- a/fs/filter/filter.go +++ b/fs/filter/filter.go @@ -433,13 +433,13 @@ func (f *Filter) MakeListR(ctx context.Context, NewObject func(ctx context.Conte var ( checkers = ci.Checkers remotes = make(chan string, checkers) - g errgroup.Group + g, gCtx = errgroup.WithContext(ctx) ) for i := 0; i < checkers; i++ { g.Go(func() (err error) { var entries = make(fs.DirEntries, 1) for remote := range remotes { - entries[0], err = NewObject(ctx, remote) + entries[0], err = NewObject(gCtx, remote) if err == fs.ErrorObjectNotFound { // Skip files that are not found } else if err != nil { @@ -454,8 +454,13 @@ func (f *Filter) MakeListR(ctx context.Context, NewObject func(ctx context.Conte return nil }) } + outer: for remote := range f.files { - remotes <- remote + select { + case remotes <- remote: + case <-gCtx.Done(): + break outer + } } close(remotes) return g.Wait() diff --git a/fs/filter/filter_test.go b/fs/filter/filter_test.go index 91723f0a0..7821cec74 100644 --- a/fs/filter/filter_test.go +++ b/fs/filter/filter_test.go @@ -360,6 +360,15 @@ func TestNewFilterMakeListR(t *testing.T) { require.NoError(t, f.AddFile("error")) err = listR(context.Background(), "", listRcallback) require.EqualError(t, err, assert.AnError.Error()) + + // The checker will exit by the error above + ci := fs.GetConfig(context.Background()) + ci.Checkers = 1 + + // Now check an error is returned from NewObject + require.NoError(t, f.AddFile("error")) + err = listR(context.Background(), "", listRcallback) + require.EqualError(t, err, assert.AnError.Error()) } func TestNewFilterMinSize(t *testing.T) {