node: allow listening on IPv6 address #27635 (#1156)

This commit is contained in:
JukLee0ira 2025-06-25 18:40:13 +08:00 committed by GitHub
parent 16f41238b8
commit 37bd0198d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View file

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
"net"
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
@ -312,7 +313,11 @@ func Setup(ctx *cli.Context) error {
// pprof server // pprof server
if ctx.Bool(pprofFlag.Name) { if ctx.Bool(pprofFlag.Name) {
address := fmt.Sprintf("%s:%d", ctx.String(pprofAddrFlag.Name), ctx.Int(pprofPortFlag.Name)) listenHost := ctx.String(pprofAddrFlag.Name)
port := ctx.Int(pprofPortFlag.Name)
address := net.JoinHostPort(listenHost, fmt.Sprintf("%d", port))
// This context value ("metrics-addr") represents the utils.MetricsHTTPFlag.Name. // This context value ("metrics-addr") represents the utils.MetricsHTTPFlag.Name.
// It cannot be imported because it will cause a cyclical dependency. // It cannot be imported because it will cause a cyclical dependency.
StartPProf(address, !ctx.IsSet("metrics-addr") && !ctx.IsSet("metrics.addr")) StartPProf(address, !ctx.IsSet("metrics-addr") && !ctx.IsSet("metrics.addr"))

View file

@ -19,6 +19,7 @@ package node
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
"net"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -246,7 +247,7 @@ func (c *Config) HTTPEndpoint() string {
if c.HTTPHost == "" { if c.HTTPHost == "" {
return "" return ""
} }
return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort) return net.JoinHostPort(c.HTTPHost, fmt.Sprintf("%d", c.HTTPPort))
} }
// DefaultHTTPEndpoint returns the HTTP endpoint used by default. // DefaultHTTPEndpoint returns the HTTP endpoint used by default.
@ -265,7 +266,7 @@ func (c *Config) WSEndpoint() string {
if c.WSHost == "" { if c.WSHost == "" {
return "" return ""
} }
return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort) return net.JoinHostPort(c.WSHost, fmt.Sprintf("%d", c.WSPort))
} }
// DefaultWSEndpoint returns the websocket endpoint used by default. // DefaultWSEndpoint returns the websocket endpoint used by default.

View file

@ -111,7 +111,7 @@ func (h *httpServer) setListenAddr(host string, port int) error {
} }
h.host, h.port = host, port h.host, h.port = host, port
h.endpoint = fmt.Sprintf("%s:%d", host, port) h.endpoint = net.JoinHostPort(host, fmt.Sprintf("%d", port))
return nil return nil
} }