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>
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]