From 57ba231c36b84c82c2f1e00639fe26bc8f4928a8 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sat, 30 Jul 2022 12:54:27 +0200 Subject: [PATCH] macos: retry if open() returns EINTR port of https://github.com/fsnotify/fsnotify/pull/475 Retry the unix.Open() if the error returned is EINTR; looking around the web it seems many systems handle it like this. This is also what os.Open() does: https://github.com/golang/go/commit/50d0ee0c98ea21f818d2daa9bc21ef51861a2ef9 --- kqueue.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kqueue.go b/kqueue.go index 11c8df5..b3ba3bc 100644 --- a/kqueue.go +++ b/kqueue.go @@ -229,8 +229,17 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) { } } - watchfd, err = unix.Open(name, openMode, 0700) - if watchfd == -1 { + // Retry on EINTR; open() can return EINTR in practice on macOS. + // See #354, and go issues 11180 and 39237. + for { + watchfd, err = unix.Open(name, openMode, 0) + if err == nil { + break + } + if errors.Is(err, unix.EINTR) { + continue + } + return "", err }