Pārlūkot izejas kodu

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 6 gadi atpakaļ
vecāks
revīzija
dfbb64ea7d
1 mainītis faili ar 1 papildinājumiem un 2 dzēšanām
  1. 1 2
      pkg/filenotify/poller.go

+ 1 - 2
pkg/filenotify/poller.go

@@ -148,12 +148,11 @@ func (w *filePoller) sendErr(e error, chClose <-chan struct{}) error {
 func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}) {
 func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}) {
 	defer f.Close()
 	defer f.Close()
 	for {
 	for {
-		time.Sleep(watchWaitTime)
 		select {
 		select {
+		case <-time.After(watchWaitTime):
 		case <-chClose:
 		case <-chClose:
 			logrus.Debugf("watch for %s closed", f.Name())
 			logrus.Debugf("watch for %s closed", f.Name())
 			return
 			return
-		default:
 		}
 		}
 
 
 		fi, err := os.Stat(f.Name())
 		fi, err := os.Stat(f.Name())