Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhuozhi authored Jun 23, 2024
2 parents d0afde6 + 02fed19 commit fe44384
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 fe44384

Please sign in to comment.