From 7b62bede1e4b8728a4d2b7a0b7a2536dbaac5099 Mon Sep 17 00:00:00 2001 From: Jason Yellick <7431583+jyellick@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:29:48 -0500 Subject: [PATCH] Log bound addresses instead of configured ones (#6948) The CLI logging currently emits the configured address when noting that the HTTP or Engine RPC services are started. This is _usually_ the same as the listening address, but not always. In particular, when the bind directive specifies an ambiguous parameter, like port 0 for an ephemeral port, the actually bound address will differ. This change will help users to operate Erigon while binding to ephemeral ports. This is especially helpful for developers trying to run multiple instances of Erigon concurrently in tests which may or may not be executing in parallel. Co-authored-by: Jason Yellick --- cmd/rpcdaemon/cli/config.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index 33e6d347e..8d489c71a 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -543,7 +543,7 @@ func startRegularRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rp return err } - listener, _, err := node.StartHTTPEndpoint(httpEndpoint, cfg.HTTPTimeouts, apiHandler) + listener, httpAddr, err := node.StartHTTPEndpoint(httpEndpoint, cfg.HTTPTimeouts, apiHandler) if err != nil { return fmt.Errorf("could not start RPC api: %w", err) } @@ -564,8 +564,10 @@ func startRegularRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rp log.Info("TCP Endpoint opened", "url", tcpEndpoint) } - info := []interface{}{"url", httpEndpoint, "ws", cfg.WebsocketEnabled, - "ws.compression", cfg.WebsocketCompression, "grpc", cfg.GRPCServerEnabled} + info := []interface{}{ + "url", httpAddr, "ws", cfg.WebsocketEnabled, + "ws.compression", cfg.WebsocketCompression, "grpc", cfg.GRPCServerEnabled, + } var ( healthServer *grpcHealth.Server @@ -594,7 +596,7 @@ func startRegularRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rp shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() _ = listener.Shutdown(shutdownCtx) - log.Info("HTTP endpoint closed", "url", httpEndpoint) + log.Info("HTTP endpoint closed", "url", httpAddr) if cfg.GRPCServerEnabled { if cfg.GRPCHealthCheckEnabled { @@ -731,13 +733,13 @@ func createEngineListener(cfg httpcfg.HttpCfg, engineApi []rpc.API) (*http.Serve return nil, nil, "", err } - engineListener, _, err := node.StartHTTPEndpoint(engineHttpEndpoint, cfg.AuthRpcTimeouts, engineApiHandler) + engineListener, engineAddr, err := node.StartHTTPEndpoint(engineHttpEndpoint, cfg.AuthRpcTimeouts, engineApiHandler) if err != nil { return nil, nil, "", fmt.Errorf("could not start RPC api: %w", err) } - engineInfo := []interface{}{"url", engineHttpEndpoint, "ws", true, "ws.compression", cfg.WebsocketCompression} + engineInfo := []interface{}{"url", engineAddr, "ws", true, "ws.compression", cfg.WebsocketCompression} log.Info("HTTP endpoint opened for Engine API", engineInfo...) - return engineListener, engineSrv, engineHttpEndpoint, nil + return engineListener, engineSrv, engineAddr.String(), nil }