mirror of https://github.com/golang/go.git
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:
parent
d0dc93c8e1
commit
f75e1c1460
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue