Skip to content

Commit

Permalink
use listen to ensure the port is free (#6990)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxjan authored Jul 4, 2021
1 parent a21d28d commit 0c685c1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func IsIPV6(ip _net.IP) bool {

// IsPortAvailable checks if a TCP port is available or not
func IsPortAvailable(p int) bool {
conn, err := _net.Dial("tcp", fmt.Sprintf(":%v", p))
ln, err := _net.Listen("tcp", fmt.Sprintf(":%v", p))
if err != nil {
return true
return false
}
defer conn.Close()
return false
defer ln.Close()
return true
}

// IsIPv6Enabled checks if IPV6 is enabled or not and we have
Expand Down

0 comments on commit 0c685c1

Please sign in to comment.