From bdaf3e5e6b87c16be02a37099e3399a54e2caaa6 Mon Sep 17 00:00:00 2001 From: Boxjan Date: Thu, 25 Mar 2021 14:08:13 +0000 Subject: [PATCH] use listen to ensure the port is free --- internal/net/net.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/net/net.go b/internal/net/net.go index b7fefb8b3b..712262f3a4 100644 --- a/internal/net/net.go +++ b/internal/net/net.go @@ -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