From abbd665e30d5a7581c95fecdeb07f6c8124773b8 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 29 Aug 2018 13:50:01 -0700 Subject: [PATCH] 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 (cherry picked from commit dfbb64ea7d042d5b2bb0c1c2b88e3682b7069b10) Upstream-commit: 3a3bfcbf47e98212abfc9cfed860d9e99fc41cdc Component: engine --- components/engine/pkg/filenotify/poller.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/engine/pkg/filenotify/poller.go b/components/engine/pkg/filenotify/poller.go index 7a9e1785c3..8f6c310e1e 100644 --- a/components/engine/pkg/filenotify/poller.go +++ b/components/engine/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{}) { defer f.Close() for { - time.Sleep(watchWaitTime) select { + case <-time.After(watchWaitTime): case <-chClose: logrus.Debugf("watch for %s closed", f.Name()) return - default: } fi, err := os.Stat(f.Name())