Skip to content

Commit 86cd9c1

Browse files
runtime: only call netpoll if netpollinited returns true
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]>
1 parent 33c246f commit 86cd9c1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/runtime/proc.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,11 @@ func mhelpgc() {
10851085
func startTheWorldWithSema(emitTraceEvent bool) int64 {
10861086
_g_ := getg()
10871087

1088-
_g_.m.locks++ // disable preemption because it can be holding p in a local var
1089-
gp := netpoll(false) // non-blocking
1090-
injectglist(gp)
1088+
_g_.m.locks++ // disable preemption because it can be holding p in a local var
1089+
if netpollinited() {
1090+
gp := netpoll(false) // non-blocking
1091+
injectglist(gp)
1092+
}
10911093
add := needaddgcproc()
10921094
lock(&sched.lock)
10931095

@@ -4237,7 +4239,7 @@ func sysmon() {
42374239
// poll network if not polled for more than 10ms
42384240
lastpoll := int64(atomic.Load64(&sched.lastpoll))
42394241
now := nanotime()
4240-
if lastpoll != 0 && lastpoll+10*1000*1000 < now {
4242+
if netpollinited() && lastpoll != 0 && lastpoll+10*1000*1000 < now {
42414243
atomic.Cas64(&sched.lastpoll, uint64(lastpoll), uint64(now))
42424244
gp := netpoll(false) // non-blocking - returns list of goroutines
42434245
if gp != nil {

0 commit comments

Comments
 (0)