fix(server): healthcheck ipv6 format is invalid (#3055)

This fixes an issue with the healthcheck writting the IPv6 host without brackets.
This commit is contained in:
James Elliott 2022-03-25 11:56:23 +11:00 committed by GitHub
parent 91a3bc6d61
commit 2f31db2db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -179,9 +179,9 @@ func Start(configuration schema.Configuration, providers middlewares.Providers)
WriteBufferSize: configuration.Server.WriteBufferSize, WriteBufferSize: configuration.Server.WriteBufferSize,
} }
addrPattern := net.JoinHostPort(configuration.Server.Host, strconv.Itoa(configuration.Server.Port)) address := net.JoinHostPort(configuration.Server.Host, strconv.Itoa(configuration.Server.Port))
listener, err := net.Listen("tcp", addrPattern) listener, err := net.Listen("tcp", address)
if err != nil { if err != nil {
logger.Fatalf("Error initializing listener: %s", err) logger.Fatalf("Error initializing listener: %s", err)
} }
@ -192,9 +192,9 @@ func Start(configuration schema.Configuration, providers middlewares.Providers)
} }
if configuration.Server.Path == "" { if configuration.Server.Path == "" {
logger.Infof("Listening for TLS connections on '%s' path '/'", addrPattern) logger.Infof("Listening for TLS connections on '%s' path '/'", address)
} else { } else {
logger.Infof("Listening for TLS connections on '%s' paths '/' and '%s'", addrPattern, configuration.Server.Path) logger.Infof("Listening for TLS connections on '%s' paths '/' and '%s'", address, configuration.Server.Path)
} }
logger.Fatal(server.ServeTLS(listener, configuration.Server.TLS.Certificate, configuration.Server.TLS.Key)) logger.Fatal(server.ServeTLS(listener, configuration.Server.TLS.Certificate, configuration.Server.TLS.Key))
@ -204,9 +204,9 @@ func Start(configuration schema.Configuration, providers middlewares.Providers)
} }
if configuration.Server.Path == "" { if configuration.Server.Path == "" {
logger.Infof("Listening for non-TLS connections on '%s' path '/'", addrPattern) logger.Infof("Listening for non-TLS connections on '%s' path '/'", address)
} else { } else {
logger.Infof("Listening for non-TLS connections on '%s' paths '/' and '%s'", addrPattern, configuration.Server.Path) logger.Infof("Listening for non-TLS connections on '%s' paths '/' and '%s'", address, configuration.Server.Path)
} }
logger.Fatal(server.Serve(listener)) logger.Fatal(server.Serve(listener))
} }

View File

@ -117,6 +117,8 @@ func writeHealthCheckEnv(disabled bool, scheme, host, path string, port int) (er
if host == "0.0.0.0" { if host == "0.0.0.0" {
host = "localhost" host = "localhost"
} else if strings.Contains(host, ":") {
host = "[" + host + "]"
} }
_, err = file.WriteString(fmt.Sprintf(healthCheckEnv, scheme, host, port, path)) _, err = file.WriteString(fmt.Sprintf(healthCheckEnv, scheme, host, port, path))