mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
boot: checkPortAvailability() should fail only for EADDRINUSE error and ignore other errors. (#2527)
fixes #2510
This commit is contained in:
parent
07506358ff
commit
45c928e2f5
@ -19,6 +19,8 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Make sure that none of the other processes are listening on the
|
// Make sure that none of the other processes are listening on the
|
||||||
@ -35,7 +37,13 @@ func checkPortAvailability(port int) error {
|
|||||||
for _, n := range network {
|
for _, n := range network {
|
||||||
l, err := net.Listen(n, fmt.Sprintf(":%d", port))
|
l, err := net.Listen(n, fmt.Sprintf(":%d", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if isAddrInUse(err) {
|
||||||
|
// Return error if another process is listening on the
|
||||||
|
// same port.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Ignore any other error (ex. EAFNOSUPPORT)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for error so we don't have dangling connection
|
// look for error so we don't have dangling connection
|
||||||
@ -46,3 +54,18 @@ func checkPortAvailability(port int) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return true if err is "address already in use" error.
|
||||||
|
// syscall.EADDRINUSE is available on all OSes.
|
||||||
|
func isAddrInUse(err error) bool {
|
||||||
|
if opErr, ok := err.(*net.OpError); ok {
|
||||||
|
if sysErr, ok := opErr.Err.(*os.SyscallError); ok {
|
||||||
|
if errno, ok := sysErr.Err.(syscall.Errno); ok {
|
||||||
|
if errno == syscall.EADDRINUSE {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user