net: deflake recently added TestCloseUnblocksReadUDP

Fixes #72802

Change-Id: I0dd457ef81a354f61c9de306e4609efdbe3d69b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/656857
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Brad Fitzpatrick 2025-03-11 21:14:01 -07:00 committed by Gopher Robot
parent 955cf0873f
commit 485480faaa
1 changed files with 15 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"net/internal/socktest"
"os"
"runtime"
"sync"
"testing"
"time"
)
@ -511,11 +512,25 @@ func TestCloseUnblocksRead(t *testing.T) {
// Issue 72770: verify that a blocked UDP read is woken up by a Close.
func TestCloseUnblocksReadUDP(t *testing.T) {
t.Parallel()
var (
mu sync.Mutex
done bool
)
defer func() {
mu.Lock()
defer mu.Unlock()
done = true
}()
pc, err := ListenPacket("udp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
time.AfterFunc(250*time.Millisecond, func() {
mu.Lock()
defer mu.Unlock()
if done {
return
}
t.Logf("closing conn...")
pc.Close()
})