From 12c63abd9d8cdfe06a4afa66ab6a6b84884b660f Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 29 Jul 2022 22:26:44 +0200 Subject: [PATCH] macos: retry if open() returns EINTR 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 Fixes #354 --- kqueue.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kqueue.go b/kqueue.go index 5247f7dc..09cefd57 100644 --- a/kqueue.go +++ b/kqueue.go @@ -237,8 +237,17 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) { } } - watchfd, err = unix.Open(name, openMode, 0) - 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 }