Skip to content

Commit 6ca3ef9

Browse files
authored
node: fix listening on IPv6 address (#27628) (#27635)
1 parent 8bbb16b commit 6ca3ef9

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

cmd/clef/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"fmt"
2828
"io"
2929
"math/big"
30+
"net"
3031
"os"
3132
"os/signal"
3233
"path/filepath"
@@ -743,7 +744,7 @@ func signer(c *cli.Context) error {
743744
port := c.Int(rpcPortFlag.Name)
744745

745746
// start http server
746-
httpEndpoint := fmt.Sprintf("%s:%d", c.String(utils.HTTPListenAddrFlag.Name), port)
747+
httpEndpoint := net.JoinHostPort(c.String(utils.HTTPListenAddrFlag.Name), fmt.Sprintf("%d", port))
747748
httpServer, addr, err := node.StartHTTPEndpoint(httpEndpoint, rpc.DefaultHTTPTimeouts, handler)
748749
if err != nil {
749750
utils.Fatalf("Could not start RPC api: %v", err)

cmd/utils/flags.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"fmt"
2727
"math"
2828
"math/big"
29+
"net"
2930
"net/http"
3031
"os"
3132
"path/filepath"
@@ -2014,7 +2015,7 @@ func SetupMetrics(ctx *cli.Context) {
20142015
}
20152016

20162017
if ctx.IsSet(MetricsHTTPFlag.Name) {
2017-
address := fmt.Sprintf("%s:%d", ctx.String(MetricsHTTPFlag.Name), ctx.Int(MetricsPortFlag.Name))
2018+
address := net.JoinHostPort(ctx.String(MetricsHTTPFlag.Name), fmt.Sprintf("%d", ctx.Int(MetricsPortFlag.Name)))
20182019
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
20192020
exp.Setup(address)
20202021
} else if ctx.IsSet(MetricsPortFlag.Name) {

internal/debug/flags.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package debug
1919
import (
2020
"fmt"
2121
"io"
22+
"net"
2223
"net/http"
2324
_ "net/http/pprof"
2425
"os"
@@ -308,7 +309,7 @@ func Setup(ctx *cli.Context) error {
308309

309310
port := ctx.Int(pprofPortFlag.Name)
310311

311-
address := fmt.Sprintf("%s:%d", listenHost, port)
312+
address := net.JoinHostPort(listenHost, fmt.Sprintf("%d", port))
312313
// This context value ("metrics.addr") represents the utils.MetricsHTTPFlag.Name.
313314
// It cannot be imported because it will cause a cyclical dependency.
314315
StartPProf(address, !ctx.IsSet("metrics.addr"))

node/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package node
1919
import (
2020
"crypto/ecdsa"
2121
"fmt"
22+
"net"
2223
"os"
2324
"path/filepath"
2425
"runtime"
@@ -263,7 +264,7 @@ func (c *Config) HTTPEndpoint() string {
263264
if c.HTTPHost == "" {
264265
return ""
265266
}
266-
return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort)
267+
return net.JoinHostPort(c.HTTPHost, fmt.Sprintf("%d", c.HTTPPort))
267268
}
268269

269270
// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
@@ -278,7 +279,7 @@ func (c *Config) WSEndpoint() string {
278279
if c.WSHost == "" {
279280
return ""
280281
}
281-
return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort)
282+
return net.JoinHostPort(c.WSHost, fmt.Sprintf("%d", c.WSPort))
282283
}
283284

284285
// DefaultWSEndpoint returns the websocket endpoint used by default.

node/rpcstack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (h *httpServer) setListenAddr(host string, port int) error {
112112
}
113113

114114
h.host, h.port = host, port
115-
h.endpoint = fmt.Sprintf("%s:%d", host, port)
115+
h.endpoint = net.JoinHostPort(host, fmt.Sprintf("%d", port))
116116
return nil
117117
}
118118

0 commit comments

Comments
 (0)