mirror of
https://github.com/golang/go.git
synced 2025-05-20 06:43:26 +00:00
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 <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
f5e475edaf
commit
f19f31f2e7
@ -14,6 +14,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -513,6 +514,15 @@ func (pq *packetQueue) send(dt *deadlineTimer, b []byte, from sockaddr, block bo
|
|||||||
if !block {
|
if !block {
|
||||||
full = pq.full
|
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 {
|
select {
|
||||||
case <-dt.expired:
|
case <-dt.expired:
|
||||||
return 0, os.ErrDeadlineExceeded
|
return 0, os.ErrDeadlineExceeded
|
||||||
@ -563,6 +573,15 @@ func (pq *packetQueue) recvfrom(dt *deadlineTimer, b []byte, wholePacket bool, c
|
|||||||
// (Without this, TestZeroByteRead deadlocks.)
|
// (Without this, TestZeroByteRead deadlocks.)
|
||||||
empty = pq.empty
|
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 {
|
select {
|
||||||
case <-dt.expired:
|
case <-dt.expired:
|
||||||
return 0, nil, os.ErrDeadlineExceeded
|
return 0, nil, os.ErrDeadlineExceeded
|
||||||
|
Loading…
x
Reference in New Issue
Block a user