Skip to content

Commit f19f31f

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
net: work around runtime scheduler starvation on js and wasip1
Fixes #65177. Updates #65178. Updates #64321. Change-Id: I698fd3b688c7dfbde692eb7c29cbdafc89e7ca32 Cq-Include-Trybots: luci.golang.try:gotip-js-wasm,gotip-wasip1-wasm_wasmtime,gotip-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]>
1 parent f5e475e commit f19f31f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/net/net_fake.go

Lines changed: 19 additions & 0 deletions
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)