]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll, runtime: handle netpollopen error in poll_runtime_pollOpen
authorTobias Klauser <tklauser@distanz.ch>
Mon, 1 Mar 2021 18:55:22 +0000 (19:55 +0100)
committerTobias Klauser <tobias.klauser@gmail.com>
Tue, 2 Mar 2021 06:08:56 +0000 (06:08 +0000)
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 #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>
src/internal/poll/fd_poll_runtime.go
src/runtime/netpoll.go

index beb0f7d6a619e164ec89700f6fcdabd8abfdf2ba..b072af00ea569e528dacc5de244bccc20fc54ded 100644 (file)
@@ -39,10 +39,6 @@ func (pd *pollDesc) init(fd *FD) error {
        serverInit.Do(runtime_pollServerInit)
        ctx, errno := runtime_pollOpen(uintptr(fd.Sysfd))
        if errno != 0 {
-               if ctx != 0 {
-                       runtime_pollUnblock(ctx)
-                       runtime_pollClose(ctx)
-               }
                return errnoErr(syscall.Errno(errno))
        }
        pd.runtimeCtx = ctx
index afb208a4550854d290d34aff5d66833465d530f1..202aef593f26b6af713c4ff089aeca53a1c3d128 100644 (file)
@@ -162,9 +162,12 @@ func poll_runtime_pollOpen(fd uintptr) (*pollDesc, int) {
        pd.self = pd
        unlock(&pd.lock)
 
-       var errno int32
-       errno = netpollopen(fd, pd)
-       return pd, int(errno)
+       errno := netpollopen(fd, pd)
+       if errno != 0 {
+               pollcache.free(pd)
+               return nil, int(errno)
+       }
+       return pd, 0
 }
 
 //go:linkname poll_runtime_pollClose internal/poll.runtime_pollClose