Skip to content

Commit f73eba7

Browse files
Bryan C. Millscagedmantis
Bryan C. Mills
authored andcommitted
[release-branch.go1.22] net: work around runtime scheduler starvation on js and wasip1
For #65883. Updates #65177. Updates #65178. Updates #64321. Change-Id: I698fd3b688c7dfbde692eb7c29cbdafc89e7ca32 Cq-Include-Trybots: luci.golang.try:go1.22-js-wasm,go1.22-wasip1-wasm_wasmtime,go1.22-wasip1-wasm_wazero Reviewed-on: https://go-review.googlesource.com/c/go/+/557037 Auto-Submit: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> (cherry picked from commit f19f31f) Reviewed-on: https://go-review.googlesource.com/c/go/+/566175 Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 5330cd2 commit f73eba7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/net/net_fake.go

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"errors"
1515
"io"
1616
"os"
17+
"runtime"
1718
"sync"
1819
"sync/atomic"
1920
"syscall"
@@ -513,6 +514,15 @@ func (pq *packetQueue) send(dt *deadlineTimer, b []byte, from sockaddr, block bo
513514
if !block {
514515
full = pq.full
515516
}
517+
518+
// Before we check dt.expired, yield to other goroutines.
519+
// This may help to prevent starvation of the goroutine that runs the
520+
// deadlineTimer's time.After callback.
521+
//
522+
// TODO(#65178): Remove this when the runtime scheduler no longer starves
523+
// runnable goroutines.
524+
runtime.Gosched()
525+
516526
select {
517527
case <-dt.expired:
518528
return 0, os.ErrDeadlineExceeded
@@ -563,6 +573,15 @@ func (pq *packetQueue) recvfrom(dt *deadlineTimer, b []byte, wholePacket bool, c
563573
// (Without this, TestZeroByteRead deadlocks.)
564574
empty = pq.empty
565575
}
576+
577+
// Before we check dt.expired, yield to other goroutines.
578+
// This may help to prevent starvation of the goroutine that runs the
579+
// deadlineTimer's time.After callback.
580+
//
581+
// TODO(#65178): Remove this when the runtime scheduler no longer starves
582+
// runnable goroutines.
583+
runtime.Gosched()
584+
566585
select {
567586
case <-dt.expired:
568587
return 0, nil, os.ErrDeadlineExceeded

0 commit comments

Comments
 (0)