Skip to content

Commit 176c98b

Browse files
committed
Revert "[common-go] backoff and retry watching files"
This reverts commit e43e0d8.
1 parent e43e0d8 commit 176c98b

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

components/common-go/watch/file.go

+8-32
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"io"
1313
"os"
1414
"path/filepath"
15-
"time"
1615

1716
"github.com/fsnotify/fsnotify"
1817

@@ -60,12 +59,6 @@ func File(ctx context.Context, path string, onChange func()) error {
6059
fw.hash = hash
6160

6261
go func() {
63-
const (
64-
initialBackoff = 100 * time.Millisecond
65-
maxBackoff = 15 * time.Second
66-
)
67-
var currentBackoff time.Duration
68-
6962
defer func() {
7063
if err != nil {
7164
log.WithError(err).Error("Stopping file watch")
@@ -90,40 +83,23 @@ func File(ctx context.Context, path string, onChange func()) error {
9083
continue
9184
}
9285

93-
currentHash, hashErr := hashConfig(path)
94-
if hashErr != nil {
95-
log.WithError(hashErr).WithField("event", event.Name).Warn("Cannot check if config has changed, backing off")
96-
97-
if currentBackoff == 0 {
98-
currentBackoff = initialBackoff
99-
} else {
100-
currentBackoff *= 2
101-
if currentBackoff > maxBackoff {
102-
currentBackoff = maxBackoff
103-
}
104-
}
105-
106-
select {
107-
case <-time.After(currentBackoff):
108-
case <-ctx.Done():
109-
log.Info("Context cancelled during backoff sleep, stopping file watcher")
110-
return
111-
}
112-
continue
86+
currentHash, err := hashConfig(path)
87+
if err != nil {
88+
log.WithError(err).WithField("event", event.Name).Warn("Cannot check if config has changed")
89+
return
11390
}
11491

115-
currentBackoff = 0
116-
92+
// no change
11793
if currentHash == fw.hash {
118-
log.WithField("path", path).Debug("Config file changed but content hash is the same")
11994
continue
12095
}
12196

12297
log.WithField("path", path).Info("reloading file after change")
98+
12399
fw.hash = currentHash
124100
fw.onChange()
125-
case watchErr := <-watcher.Errors:
126-
log.WithError(watchErr).Error("Unexpected error watching event")
101+
case err := <-watcher.Errors:
102+
log.WithError(err).Error("Unexpected error watching event")
127103
case <-ctx.Done():
128104
return
129105
}

0 commit comments

Comments
 (0)