Skip to content

Commit

Permalink
chore: fix bind err when test (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaost committed Jun 21, 2024
1 parent a45de35 commit 02fed19
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/test/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,12 @@ func GetLocalAddress() string {

// tells if a net address is already in use.
func IsAddressInUse(address string) bool {
// Attempt to establish a TCP connection to the address
conn, err := net.DialTimeout("tcp", address, time.Duration(1+rand.Intn(10))*100*time.Millisecond)
ln, err := net.Listen("tcp", address)
if err != nil {
// If there's an error, the address is likely not in use or not reachable
return false
return true
}
_ = conn.Close()
// If the connection is successful, the address is in use
return true
ln.Close()
return false
}

// WaitServerStart waits for server to start for at most 1 second
Expand Down

0 comments on commit 02fed19

Please sign in to comment.