]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: only call netpoll if netpollinited returns true
authorIan Lance Taylor <iant@golang.org>
Tue, 7 Nov 2017 04:51:36 +0000 (20:51 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 7 Nov 2017 16:18:12 +0000 (16:18 +0000)
This fixes a race on old Linux kernels, in which we might temporarily
set epfd to an invalid value other than -1. It's also the right thing
to do. No test because the problem only occurs on old kernels.

Fixes #22606

Change-Id: Id84bdd6ae6d7c5d47c39e97b74da27576cb51a54
Reviewed-on: https://go-review.googlesource.com/76319
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
src/runtime/proc.go

index 112543db10850a64eafa7f7c04f40935b8f4ed45..8adf3b27252697bbd87542ef58666dc6761dd50d 100644 (file)
@@ -1085,9 +1085,11 @@ func mhelpgc() {
 func startTheWorldWithSema(emitTraceEvent bool) int64 {
        _g_ := getg()
 
-       _g_.m.locks++        // disable preemption because it can be holding p in a local var
-       gp := netpoll(false) // non-blocking
-       injectglist(gp)
+       _g_.m.locks++ // disable preemption because it can be holding p in a local var
+       if netpollinited() {
+               gp := netpoll(false) // non-blocking
+               injectglist(gp)
+       }
        add := needaddgcproc()
        lock(&sched.lock)
 
@@ -4237,7 +4239,7 @@ func sysmon() {
                // poll network if not polled for more than 10ms
                lastpoll := int64(atomic.Load64(&sched.lastpoll))
                now := nanotime()
-               if lastpoll != 0 && lastpoll+10*1000*1000 < now {
+               if netpollinited() && lastpoll != 0 && lastpoll+10*1000*1000 < now {
                        atomic.Cas64(&sched.lastpoll, uint64(lastpoll), uint64(now))
                        gp := netpoll(false) // non-blocking - returns list of goroutines
                        if gp != nil {