Skip to content

Commit ebb92df

Browse files
committed
internal/poll, runtime: handle netpollopen error in poll_runtime_pollOpen
When netpollopen in poll_runtime_pollOpen returns an error, the work in runtime_pollUnblock and runtime_pollClose can be avoided since the underlying system call to set up the poller failed. E.g. on linux, this avoids calling netpollclose and thus epoll_ctl(fd, EPOLL_CTL_DEL, ...) in case the file does not support epoll, i.e. epoll_ctl(fd, EPOLL_CTL_ADD, ...) in netpollopen failed. Fixes golang#44552 Change-Id: I564d90340fd1ab3a6490526353616a447ae0cfb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/297392 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 4c1a7ab commit ebb92df

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/internal/poll/fd_poll_runtime.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ func (pd *pollDesc) init(fd *FD) error {
3939
serverInit.Do(runtime_pollServerInit)
4040
ctx, errno := runtime_pollOpen(uintptr(fd.Sysfd))
4141
if errno != 0 {
42-
if ctx != 0 {
43-
runtime_pollUnblock(ctx)
44-
runtime_pollClose(ctx)
45-
}
4642
return errnoErr(syscall.Errno(errno))
4743
}
4844
pd.runtimeCtx = ctx

src/runtime/netpoll.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ func poll_runtime_pollOpen(fd uintptr) (*pollDesc, int) {
162162
pd.self = pd
163163
unlock(&pd.lock)
164164

165-
var errno int32
166-
errno = netpollopen(fd, pd)
167-
return pd, int(errno)
165+
errno := netpollopen(fd, pd)
166+
if errno != 0 {
167+
pollcache.free(pd)
168+
return nil, int(errno)
169+
}
170+
return pd, 0
168171
}
169172

170173
//go:linkname poll_runtime_pollClose internal/poll.runtime_pollClose

0 commit comments

Comments
 (0)