Skip to content

Commit

Permalink
macos: retry if open() returns EINTR (#475)
Browse files Browse the repository at this point in the history
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:
golang/go@50d0ee0

Fixes #354
  • Loading branch information
arp242 committed Jul 30, 2022
1 parent ff39bb4 commit ca0e2f4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions kqueue.go
Expand Up @@ -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
}

Expand Down

0 comments on commit ca0e2f4

Please sign in to comment.