aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2024-01-19 16:51:24 -0500
committerCarlos Amedee <carlos@golang.org>2024-02-28 19:44:18 +0000
commitf73eba76a04f5a4c8a1ba1382c6c4ade7b21e720 (patch)
tree7a6e366946ecd45ec30edd1ff89859110e8cff31
parent5330cd225ba54c7dc78c1b46dcdf61a4671a632c (diff)
downloadgo-f73eba76a04f5a4c8a1ba1382c6c4ade7b21e720.tar.gz
[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 <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> (cherry picked from commit f19f31f2e7c136a8dae03cbfe4f8ebbb8b54569b) Reviewed-on: https://go-review.googlesource.com/c/go/+/566175 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
-rw-r--r--src/net/net_fake.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/net/net_fake.go b/src/net/net_fake.go
index 6b6fdc728e..525ff32296 100644
--- a/src/net/net_fake.go
+++ b/src/net/net_fake.go
@@ -14,6 +14,7 @@ import (
"errors"
"io"
"os"
+ "runtime"
"sync"
"sync/atomic"
"syscall"
@@ -513,6 +514,15 @@ func (pq *packetQueue) send(dt *deadlineTimer, b []byte, from sockaddr, block bo
if !block {
full = pq.full
}
+
+ // Before we check dt.expired, yield to other goroutines.
+ // This may help to prevent starvation of the goroutine that runs the
+ // deadlineTimer's time.After callback.
+ //
+ // TODO(#65178): Remove this when the runtime scheduler no longer starves
+ // runnable goroutines.
+ runtime.Gosched()
+
select {
case <-dt.expired:
return 0, os.ErrDeadlineExceeded
@@ -563,6 +573,15 @@ func (pq *packetQueue) recvfrom(dt *deadlineTimer, b []byte, wholePacket bool, c
// (Without this, TestZeroByteRead deadlocks.)
empty = pq.empty
}
+
+ // Before we check dt.expired, yield to other goroutines.
+ // This may help to prevent starvation of the goroutine that runs the
+ // deadlineTimer's time.After callback.
+ //
+ // TODO(#65178): Remove this when the runtime scheduler no longer starves
+ // runnable goroutines.
+ runtime.Gosched()
+
select {
case <-dt.expired:
return 0, nil, os.ErrDeadlineExceeded