]> Cypherpunks repositories - gostls13.git/commitdiff
net: report timeouts more aggressively in Accept in the fake implementation
authorBryan C. Mills <bcmills@google.com>
Mon, 22 Jan 2024 23:02:38 +0000 (18:02 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 23 Jan 2024 17:05:09 +0000 (17:05 +0000)
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>
src/net/net_fake.go

index 60b52b79fd0e78a5b86cf33cf3c42cb0c944a39a..b7ecb391448a2c75c16bf2f7d28fc0cde00a5dd5 100644 (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]