From 3cd1b20236a962cdf1425bc0dc0830d1f1457e19 Mon Sep 17 00:00:00 2001 From: Max Sum Date: Tue, 3 Dec 2019 13:37:02 +0800 Subject: [PATCH] union: add cancel to ctx --- backend/union/policy/newest.go | 3 ++- backend/union/upstream/upstream.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/union/policy/newest.go b/backend/union/policy/newest.go index b380eaad4..c8fd4f47a 100644 --- a/backend/union/policy/newest.go +++ b/backend/union/policy/newest.go @@ -52,7 +52,8 @@ func (p *Newest) newest(ctx context.Context, upstreams []*upstream.Fs, path stri func (p *Newest) newestEntries(entries []upstream.Entry) (upstream.Entry, error) { var wg sync.WaitGroup mtimes := make([]time.Time, len(entries)) - ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() for i, e := range entries { wg.Add(1) i, e := i, e // Closure diff --git a/backend/union/upstream/upstream.go b/backend/union/upstream/upstream.go index ada593179..39581c3e7 100644 --- a/backend/union/upstream/upstream.go +++ b/backend/union/upstream/upstream.go @@ -307,7 +307,8 @@ func (f *Fs) updateUsageCore(lock bool) error { defer f.cacheMutex.Unlock() } // Run in background, should not be cancelled by user - ctx, _ := context.WithTimeout(context.Background(), 15*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() usage, err := f.Features().About(ctx) if err != nil { return err