use listen to ensure the port is free (#6990) (#7467)

Co-authored-by: boxjan <i@boxjan.li>
This commit is contained in:
Eugene Apollonsky 2021-08-09 15:31:31 +03:00 committed by GitHub
parent 98288bc3ca
commit af745bd97d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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