Просмотр исходного кода

lib/model, lib/scanner: Prevent races aborting scans (fixes #6994) (#6997)

Simon Frei 5 лет назад
Родитель
Сommit
8452fd2ab4
2 измененных файлов с 9 добавлено и 0 удалено
  1. 5 0
      lib/model/folder.go
  2. 4 0
      lib/scanner/blockqueue.go

+ 5 - 0
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
 		}
 

+ 4 - 0
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)
 	}