fix: do port availability check only on macOS. (#3654)

On macOS, if a process already listens on 127.0.0.1:PORT, net.Listen() falls back
to IPv6 address ie minio will start listening on IPv6 address whereas another
(non-)minio process is listening on IPv4 of given port.
To avoid this error sutiation we check for port availability only for macOS.

Note: checkPortAvailability() tries to listen on given port and closes it.
It is possible to have a disconnected client in this tiny window of time.
This commit is contained in:
Bala FA
2017-01-30 14:14:36 +05:30
committed by Harshavardhana
parent b408d0e87d
commit cc1575f944
2 changed files with 13 additions and 20 deletions

View File

@@ -352,9 +352,14 @@ func getHostPort(address string) (host, port string, err error) {
return "", "", err
}
// Check if port is available.
if err = checkPortAvailability(port); err != nil {
return "", "", err
if runtime.GOOS == "darwin" {
// On macOS, if a process already listens on 127.0.0.1:PORT, net.Listen() falls back
// to IPv6 address ie minio will start listening on IPv6 address whereas another
// (non-)minio process is listening on IPv4 of given port.
// To avoid this error sutiation we check for port availability only for macOS.
if err = checkPortAvailability(port); err != nil {
return "", "", err
}
}
// Success.