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 net.Listen func to ensure the port is free #6990

Merged
merged 1 commit into from
Jul 4, 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant it be a problem if we try to bind nginx to a specific IP, but here you check all the interfaces?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#bind-address <- we should probably check against this address specifically:

  1. If it does not exists, we may try binding to every address
  2. If this exists, then we should try to bind specifically to this address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, I just did a workaround let it can run in my cluster. I will try to change it under your suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rikatz but the function was use in init check, so it will change so many things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum indeed, this value is in ConfigMap and it's not a flag...

OK, so overall this problem would still happen if we have something listening in the port, I think we can go forward with this one.

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