From 6a19d7b25a891b4fec06ed751ae63d5ba24f4afb Mon Sep 17 00:00:00 2001 From: Yao Zongyou Date: Wed, 2 Oct 2019 01:42:18 +0800 Subject: [PATCH] skip checking error also on Mac in TestCheckPortAvailability (#8343) --- cmd/globals.go | 1 + cmd/net.go | 16 +--------------- cmd/net_test.go | 4 ++-- 3 files changed, 4 insertions(+), 17 deletions(-) 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 }