diff --git a/cmd/globals.go b/cmd/globals.go index 5da16a471..d5f0711b6 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -58,6 +58,7 @@ const ( globalMinioDefaultStorageClass = "STANDARD" globalWindowsOSName = "windows" globalNetBSDOSName = "netbsd" + globalMacOSName = "darwin" globalMinioModeFS = "mode-server-fs" globalMinioModeXL = "mode-server-xl" globalMinioModeDistXL = "mode-server-distributed-xl" diff --git a/cmd/net.go b/cmd/net.go index f343ba7e9..dadccc334 100644 --- a/cmd/net.go +++ b/cmd/net.go @@ -21,7 +21,6 @@ import ( "fmt" "net" "net/url" - "os" "sort" "strconv" "strings" @@ -194,19 +193,6 @@ func isHostIP(ipAddress string) bool { // Note: The check method tries to listen on given port and closes it. // It is possible to have a disconnected client in this tiny window of time. func checkPortAvailability(host, port string) (err error) { - // Return true if err is "address already in use" error. - isAddrInUseErr := func(err error) (b bool) { - if opErr, ok := err.(*net.OpError); ok { - if sysErr, ok := opErr.Err.(*os.SyscallError); ok { - if errno, ok := sysErr.Err.(syscall.Errno); ok { - b = (errno == syscall.EADDRINUSE) - } - } - } - - return b - } - network := []string{"tcp", "tcp4", "tcp6"} for _, n := range network { l, err := net.Listen(n, net.JoinHostPort(host, port)) @@ -216,7 +202,7 @@ func checkPortAvailability(host, port string) (err error) { if err = l.Close(); err != nil { return err } - } else if isAddrInUseErr(err) { + } else if errors.Is(err, syscall.EADDRINUSE) { // As we got EADDRINUSE error, the port is in use by other process. // Return the error. return err diff --git a/cmd/net_test.go b/cmd/net_test.go index ecbfc94e1..ee5e9d21c 100644 --- a/cmd/net_test.go +++ b/cmd/net_test.go @@ -216,8 +216,8 @@ func TestCheckPortAvailability(t *testing.T) { } for _, testCase := range testCases { - // On MS Windows, skip checking error case due to https://github.com/golang/go/issues/7598 - if runtime.GOOS == globalWindowsOSName && testCase.expectedErr != nil { + // On MS Windows and Mac, skip checking error case due to https://github.com/golang/go/issues/7598 + if (runtime.GOOS == globalWindowsOSName || runtime.GOOS == globalMacOSName) && testCase.expectedErr != nil { continue }