Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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