Skip to content

Commit

Permalink
log errors after last pull iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
imsodin committed Jul 2, 2020
1 parent 77a532e commit 13de499
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/model/folder_sendrecv.go
Expand Up @@ -138,9 +138,9 @@ type sendReceiveFolder struct {
blockPullReorderer blockPullReorderer
writeLimiter *byteSemaphore

pullErrors map[string]string // errors for most recent/current iteration
oldPullErrors map[string]string // errors from previous iterations for log filtering only
pullErrorsMut sync.Mutex
pullErrors map[string]string // actual exposed pull errors
tempPullErrors map[string]string // pull errors that might be just transient
pullErrorsMut sync.Mutex
}

func newSendReceiveFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg config.FolderConfiguration, ver versioner.Versioner, fs fs.Filesystem, evLogger events.Logger, ioLimiter *byteSemaphore) service {
Expand Down Expand Up @@ -202,6 +202,10 @@ func (f *sendReceiveFolder) pull() bool {

changed := 0

f.pullErrorsMut.Lock()
f.pullErrors = nil
f.pullErrorsMut.Unlock()

for tries := 0; tries < maxPullerIterations; tries++ {
select {
case <-f.ctx.Done():
Expand All @@ -226,8 +230,14 @@ func (f *sendReceiveFolder) pull() bool {
}

f.pullErrorsMut.Lock()
f.pullErrors = f.tempPullErrors
f.tempPullErrors = nil
for path, err := range f.pullErrors {
l.Infof("Puller (folder %s, item %q): %v", f.Description(), path, err)
}
pullErrNum := len(f.pullErrors)
f.pullErrorsMut.Unlock()

if pullErrNum > 0 {
l.Infof("%v: Failed to sync %v items", f.Description(), pullErrNum)
f.evLogger.Log(events.FolderErrors, map[string]interface{}{
Expand All @@ -245,8 +255,7 @@ func (f *sendReceiveFolder) pull() bool {
// flagged as needed in the folder.
func (f *sendReceiveFolder) pullerIteration(scanChan chan<- string) int {
f.pullErrorsMut.Lock()
f.oldPullErrors = f.pullErrors
f.pullErrors = make(map[string]string)
f.tempPullErrors = make(map[string]string)
f.pullErrorsMut.Unlock()

snap := f.fset.Snapshot()
Expand Down Expand Up @@ -316,10 +325,6 @@ func (f *sendReceiveFolder) pullerIteration(scanChan chan<- string) int {
close(dbUpdateChan)
updateWg.Wait()

f.pullErrorsMut.Lock()
f.oldPullErrors = nil
f.pullErrorsMut.Unlock()

f.queue.Reset()

return changed
Expand Down Expand Up @@ -1835,23 +1840,17 @@ func (f *sendReceiveFolder) newPullError(path string, err error) {
// We might get more than one error report for a file (i.e. error on
// Write() followed by Close()); we keep the first error as that is
// probably closer to the root cause.
if _, ok := f.pullErrors[path]; ok {
if _, ok := f.tempPullErrors[path]; ok {
return
}

// Establish context to differentiate from errors while scanning.
// Use "syncing" as opposed to "pulling" as the latter might be used
// for errors occurring specificly in the puller routine.
errStr := fmt.Sprintln("syncing:", err)
f.pullErrors[path] = errStr

if oldErr, ok := f.oldPullErrors[path]; ok && oldErr == errStr {
l.Debugf("Repeat error on puller (folder %s, item %q): %v", f.Description(), path, err)
delete(f.oldPullErrors, path) // Potential repeats are now caught by f.pullErrors itself
return
}
f.tempPullErrors[path] = errStr

l.Infof("Puller (folder %s, item %q): %v", f.Description(), path, err)
l.Debugln("%v new error for %v: %v", f, path, err)
}

func (f *sendReceiveFolder) Errors() []FileError {
Expand Down
1 change: 1 addition & 0 deletions lib/model/folder_sendrecv_test.go
Expand Up @@ -97,6 +97,7 @@ func setupSendReceiveFolder(files ...protocol.FileInfo) (*model, *sendReceiveFol
model.Supervisor.Stop()
f := model.folderRunners[fcfg.ID].(*sendReceiveFolder)
f.pullErrors = make(map[string]string)
f.tempPullErrors = make(map[string]string)
f.ctx = context.Background()

// Update index
Expand Down

0 comments on commit 13de499

Please sign in to comment.