1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-12 22:10:14 +00:00

fix(analyze): fix scan deadlock with non-blocking fallback and add regression test (#419)

This commit is contained in:
tw93
2026-02-07 11:01:00 +08:00
parent 5cdfcf2479
commit 95b3818da8
2 changed files with 51 additions and 7 deletions

View File

@@ -351,14 +351,20 @@ func calculateDirSizeFast(root string, filesScanned, dirsScanned, bytesScanned *
for _, entry := range entries {
if entry.IsDir() {
subDir := filepath.Join(dirPath, entry.Name())
sem <- struct{}{}
wg.Add(1)
go func(p string) {
defer wg.Done()
defer func() { <-sem }()
walk(p)
}(subDir)
atomic.AddInt64(dirsScanned, 1)
select {
case sem <- struct{}{}:
wg.Add(1)
go func(p string) {
defer wg.Done()
defer func() { <-sem }()
walk(p)
}(subDir)
default:
// Fallback to synchronous traversal to avoid semaphore deadlock under high fan-out.
walk(subDir)
}
} else {
info, err := entry.Info()
if err == nil {