Skip to content

Commit 240c185

Browse files
chessmanboxjan
authored andcommitted
use listen to ensure the port is free (kubernetes#6990) (kubernetes#7467)
Co-authored-by: boxjan <[email protected]>
1 parent 0f2e88e commit 240c185

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/net/net.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func IsIPV6(ip _net.IP) bool {
2929

3030
// IsPortAvailable checks if a TCP port is available or not
3131
func IsPortAvailable(p int) bool {
32-
conn, err := _net.Dial("tcp", fmt.Sprintf(":%v", p))
32+
ln, err := _net.Listen("tcp", fmt.Sprintf(":%v", p))
3333
if err != nil {
34-
return true
34+
return false
3535
}
36-
defer conn.Close()
37-
return false
36+
defer ln.Close()
37+
return true
3838
}
3939

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

0 commit comments

Comments
 (0)