From 8452fd2ab4873801440d4d5a0460f8072da486c1 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 25 Sep 2020 11:27:44 +0200 Subject: [PATCH] lib/model, lib/scanner: Prevent races aborting scans (fixes #6994) (#6997) --- lib/model/folder.go | 5 +++++ lib/scanner/blockqueue.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/model/folder.go b/lib/model/folder.go index ffd167ab1..e77726c3c 100644 --- a/lib/model/folder.go +++ b/lib/model/folder.go @@ -520,6 +520,11 @@ func (f *folder) scanSubdirs(subDirs []string) error { } if err := batch.flushIfFull(); err != nil { + // Prevent a race between the scan aborting due to context + // cancellation and releasing the snapshot in defer here. + scanCancel() + for range fchan { + } return err } diff --git a/lib/scanner/blockqueue.go b/lib/scanner/blockqueue.go index 6c22714c2..a56187535 100644 --- a/lib/scanner/blockqueue.go +++ b/lib/scanner/blockqueue.go @@ -136,6 +136,10 @@ func (ph *parallelHasher) hashFiles(ctx context.Context) { func (ph *parallelHasher) closeWhenDone() { ph.wg.Wait() + // In case the hasher aborted on context, wait for filesystem + // walking/progress routine to finish. + for range ph.inbox { + } if ph.done != nil { close(ph.done) }