Skip to content

Commit

Permalink
Log slow to process files
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Nov 30, 2021
1 parent fc1157a commit 9282641
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/folder-torture/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func doRandomFileOperation(dir string) {
log.Printf("write tmp file failed %v: %v", fileName, err)
return
}
log.Printf("made file", fileName)
log.Printf("made file %v", fileName)

// move a directory
case choice < 8:
Expand Down
32 changes: 24 additions & 8 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"strings"
Expand All @@ -20,6 +21,10 @@ const (
timeLimit = 250 * time.Millisecond
)

var (
currentPath = ""
)

func hashFile(path string) ([]byte, error) {
content, err := os.ReadFile(path)
if err != nil {
Expand Down Expand Up @@ -84,6 +89,8 @@ func WalkChan(dir string, ignores []string) <-chan *Entry {
emptyDirMode := fs.FileMode(0)

filepath.WalkDir(dir, func(path string, entry fs.DirEntry, err error) error {
currentPath = path

if maybeEmptyDir != "" {
if !strings.HasPrefix(path, filepath.Join(dir, maybeEmptyDir)) {
pushEmptyDir(maybeEmptyDir, emptyDirMode)
Expand Down Expand Up @@ -215,15 +222,24 @@ func readFromChan(info *channelInfo) (*Entry, bool) {
}, false
}

select {
case entry, open := <-info.channel:
info.count += 1
return entry, open
case <-time.After(timeLimit):
return &Entry{
err: fmt.Errorf("timeout waiting for entry from: %v", info.name),
}, false
for i := 0; i < 3; i++ {
select {
case entry, open := <-info.channel:
info.count += 1
return entry, open
case <-time.After(timeLimit):
if info.name == "walk" {
log.Printf("single file timeout elapsed for %v from the filesystem channel", currentPath)
} else {
log.Printf("single file timeout elapsed from the %v channel", info.name)
}

}
}

return &Entry{
err: fmt.Errorf("timeout waiting for entry from: %v", info.name),
}, false
}

func Diff(walkC, sumC <-chan *Entry) (*pb.Diff, *pb.Summary, error) {
Expand Down

0 comments on commit 9282641

Please sign in to comment.