]> go.fuhry.dev Git - fsnotify.git/commitdiff
macos: retry if open() returns EINTR (#475)
authorMartin Tournoij <martin@arp242.net>
Sat, 30 Jul 2022 10:54:27 +0000 (12:54 +0200)
committerGitHub <noreply@github.com>
Sat, 30 Jul 2022 10:54:27 +0000 (12:54 +0200)
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

index 5247f7dcf0386ba7f675904d4255363a10eba375..09cefd574199e80528a8e8e565c7719ba11757d7 100644 (file)
--- 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
                }