net: report timeouts more aggressively in Accept in the fake implementation

This ensures that if the listener has already timed out when Accept
is called, Accept always returns an error instead of instantaneously
accepting a connection that was already pending.

For #17948.

Change-Id: Iabef7121590df3dcc2fe428429d7c2bc2bcb6cd5
Reviewed-on: https://go-review.googlesource.com/c/go/+/557438
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Bryan C. Mills 2024-01-22 18:02:38 -05:00 committed by Gopher Robot
parent d0dc93c8e1
commit f75e1c1460
1 changed files with 14 additions and 1 deletions

View File

@ -325,14 +325,27 @@ func (ffd *fakeNetFD) accept(laddr Addr) (*netFD, error) {
incoming []*netFD
ok bool
)
expired := ffd.readDeadline.Load().expired
select {
case <-ffd.readDeadline.Load().expired:
case <-expired:
return nil, os.ErrDeadlineExceeded
case incoming, ok = <-ffd.incoming:
if !ok {
return nil, ErrClosed
}
select {
case <-expired:
ffd.incoming <- incoming
return nil, os.ErrDeadlineExceeded
default:
}
case incoming, ok = <-ffd.incomingFull:
select {
case <-expired:
ffd.incomingFull <- incoming
return nil, os.ErrDeadlineExceeded
default:
}
}
peer := incoming[0]