From: Richard Miller Date: Sat, 13 Jun 2020 18:04:15 +0000 (+0100) Subject: runtime: avoid lock starvation in TestNetpollBreak on Plan 9 X-Git-Tag: go1.15rc1~106 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9340bd610bfd386f8a71e480019b44806d53c3db;p=gostls13.git runtime: avoid lock starvation in TestNetpollBreak on Plan 9 TestNetpollBreak was sometimes timing out on Plan 9, where netpoll_stub.go implements only enough of the network poller to support runtime timers, using a notetsleep / notewakeup pair. The runtime.lock which serialises the use of the note doesn't guarantee fairness, and in practice the netpoll call used by the test can be starved by the netpoll call from the scheduler which supports the overall 'go test' timeout. Calling osyield after relinquishing the lock gives the two callers a more even chance to take a turn, which prevents the test from timing out. Fixes #39437 Change-Id: Ifbe6aaf95336d162d9d0b6deba19b8debf17b071 Reviewed-on: https://go-review.googlesource.com/c/go/+/237698 Run-TryBot: David du Colombier <0intro@gmail.com> Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/netpoll_stub.go b/src/runtime/netpoll_stub.go index f86f2f6174..3599f2d01b 100644 --- a/src/runtime/netpoll_stub.go +++ b/src/runtime/netpoll_stub.go @@ -49,6 +49,9 @@ func netpoll(delay int64) gList { notetsleep(&netpollNote, delay) unlock(&netpollStubLock) + // Guard against starvation in case the lock is contended + // (eg when running TestNetpollBreak). + osyield() } return gList{} }