Browse code

pkg/filenotify/poller: close file asap

There is no need to wait for up to 200ms in order to close
the file descriptor once the chClose is received.

This commit might reduce the chances for occasional "The process
cannot access the file because it is being used by another process"
error on Windows, where an opened file can't be removed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/08/30 05:50:01
Showing 1 changed files
... ...
@@ -148,12 +148,11 @@ func (w *filePoller) sendErr(e error, chClose <-chan struct{}) error {
148 148
 func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}) {
149 149
 	defer f.Close()
150 150
 	for {
151
-		time.Sleep(watchWaitTime)
152 151
 		select {
152
+		case <-time.After(watchWaitTime):
153 153
 		case <-chClose:
154 154
 			logrus.Debugf("watch for %s closed", f.Name())
155 155
 			return
156
-		default:
157 156
 		}
158 157
 
159 158
 		fi, err := os.Stat(f.Name())