Skip to content

Commit 059f2d4

Browse files
paulzholianlancetaylor
authored andcommitted
os: disable the use of netpoll on directories as well on *BSDs
Follow up CL 156379. Updates #19093 Change-Id: I5ea3177fc5911d3af71cbb32584249e419e9d4a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/172937 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 14b5b4a commit 059f2d4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/os/file_unix.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,27 @@ func newFile(fd uintptr, name string, kind newFileKind) *File {
122122
// we assume they know what they are doing so we allow it to be
123123
// used with kqueue.
124124
if kind == kindOpenFile {
125-
var st syscall.Stat_t
126125
switch runtime.GOOS {
127-
case "dragonfly", "freebsd", "netbsd", "openbsd":
126+
case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd":
127+
var st syscall.Stat_t
128+
err := syscall.Fstat(fdi, &st)
129+
typ := st.Mode & syscall.S_IFMT
128130
// Don't try to use kqueue with regular files on *BSDs.
129131
// On FreeBSD a regular file is always
130132
// reported as ready for writing.
131133
// On Dragonfly, NetBSD and OpenBSD the fd is signaled
132134
// only once as ready (both read and write).
133135
// Issue 19093.
134-
if err := syscall.Fstat(fdi, &st); err == nil && st.Mode&syscall.S_IFMT == syscall.S_IFREG {
136+
// Also don't add directories to the netpoller.
137+
if err == nil && (typ == syscall.S_IFREG || typ == syscall.S_IFDIR) {
135138
pollable = false
136139
}
137140

138-
case "darwin":
139141
// In addition to the behavior described above for regular files,
140142
// on Darwin, kqueue does not work properly with fifos:
141143
// closing the last writer does not cause a kqueue event
142144
// for any readers. See issue #24164.
143-
if err := syscall.Fstat(fdi, &st); err == nil && (st.Mode&syscall.S_IFMT == syscall.S_IFIFO || st.Mode&syscall.S_IFMT == syscall.S_IFREG) {
145+
if runtime.GOOS == "darwin" && typ == syscall.S_IFIFO {
144146
pollable = false
145147
}
146148
}

0 commit comments

Comments
 (0)