From 6603e57968d1ede6a807be2705ae7ca4e7e8e58e Mon Sep 17 00:00:00 2001 From: Aproc Date: Fri, 14 Jun 2024 15:08:19 +0800 Subject: [PATCH] fix(testutil/WaitForPort ): conn.Close panic with nil Point --- testutil/testutil.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testutil/testutil.go b/testutil/testutil.go index ea8a69b..66da966 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -29,11 +29,12 @@ func AwaitCondition(cond util.Condition, period time.Duration, maxWait time.Dura // run are ready.d func WaitForPort(t *testing.T, port int) error { err := AwaitCondition(func() bool { - conn, err := net.Dial("tcp", "localhost:"+strconv.Itoa(port)) - if err != nil { + conn, _ := net.Dial("tcp", "localhost:"+strconv.Itoa(port)) + if conn != nil { conn.Close() + return true } - return err != nil + return false }, 500*time.Millisecond, 60*time.Second) return err }