From 996716a8e2d538da36f4f1553cf4874fe469d20c Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Tue, 22 Aug 2017 13:33:19 -0700 Subject: [PATCH] Fix hanging of finder_test Previously there could be an infinite loop in the Finder's db export when running tests on a system with few cores. The Finder divides the cache-serialization work amongst cores. On systems with enough cores, each path in TestFileSystemRoot would get its own core and the infinite loop in the prefix calculation logic would be avoided. On systems with fewer cores, the computation of the maximum common path could run forever. This shouldn't have affected the general usage of the Finder in builds other than in its unit tests, because the builds don't ask to include the filesystem root as a path to scan. This should only have affected finder_test.go which tested the filesystem root anyway. Bug: 62455338 Test: m -j # which runs unit tests Change-Id: I7a1467fb32e4538fb96833791180bfbfad5a3911 --- finder/finder.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/finder/finder.go b/finder/finder.go index 8f9496d38..c2df92892 100644 --- a/finder/finder.go +++ b/finder/finder.go @@ -661,6 +661,9 @@ func (f *Finder) serializeCacheEntry(dirInfos []dirFullInfo) ([]byte, error) { for _, info := range infos { for !strings.HasPrefix(info.P+"/", prefix+"/") { prefix = filepath.Dir(prefix) + if prefix == "/" { + break + } } } // remove common prefix