runtime: netpollWaiters typically not decremented #33624
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What is the semantic of runtime.netpollWaiters?
If it should track number of goroutines waiting for poll result, then it is implemented incorrectly (at least on Linux with epoll).
I see that runtime.netpollWaiters is incremented every time new goroutine getting blocked on polling:
go/src/runtime/netpoll.go
Lines 354 to 363 in f686a28
and decremented only in
func netpollgoready(gp *g, traceskip int)
:go/src/runtime/netpoll.go
Lines 365 to 368 in f686a28
Looks like
netpollgoready()
is called only frominternal/poll.runtime_pollSetDeadline()
, i.e. in some codepaths related to setting polling deadlines:go/src/runtime/netpoll.go
Lines 204 to 205 in f686a28
And most frequently parked goroutine waiting for poll result is being awakened somewhere in
runtime.findrunnable()
:go/src/runtime/proc.go
Lines 2210 to 2221 in 61bb56a
or
runtime.pollWork()
:go/src/runtime/proc.go
Lines 2395 to 2409 in 61bb56a
Apparently
atomic.Load(&netpollWaiters) > 0
condition in the referenced aboveruntime.findrunnable()
andruntime.pollWork()
functions is always true, as soon as as single goroutine will wait for poll result and get awakened from those functions.I verified that
runtime.netpollWaiters
is increased with each wait of a goroutine on network in an example of handling TCP conection:Snippet from
go env
:The text was updated successfully, but these errors were encountered: