From 9e5c4df1064a430274eff036509153ff36ed1145 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Fri, 7 Sep 2018 05:12:33 +0530 Subject: [PATCH] Gateway should honour --address flag while checking port availability (#6428) Fixes #6426 --- cmd/gateway-main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 1795e679b..aedfe6d34 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -19,6 +19,7 @@ package cmd import ( "context" "fmt" + "net" "net/url" "os" "os/signal" @@ -136,11 +137,17 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // Handle common env vars. handleCommonEnvVars() + // Get port to listen on from gateway address + _, gatewayPort, pErr := net.SplitHostPort(gatewayAddr) + if pErr != nil { + logger.FatalIf(pErr, "Unable to start gateway") + } + // On macOS, if a process already listens on LOCALIPADDR: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 situation we check for port availability. - logger.FatalIf(checkPortAvailability(globalMinioPort), "Unable to start the server") + logger.FatalIf(checkPortAvailability(gatewayPort), "Unable to start the gateway") // Validate if we have access, secret set through environment. if !globalIsEnvCreds {