Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: Add warning if EndpointAddress and NetAddress ports are equal #6006

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions daemon/algod/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net"
"net/http"
_ "net/http/pprof" // net/http/pprof is for registering the pprof URLs with the web server, so http://localhost:8080/debug/pprof/ works.
"net/url"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -269,6 +270,19 @@ func makeListener(addr string) (net.Listener, error) {
return net.Listen("tcp", addr)
}

// helper to get port from an address
func getPortFromAddress(addr string) (string, error) {
u, err := url.Parse(addr)
if err == nil && u.Scheme != "" {
addr = u.Host
}
_, port, err := net.SplitHostPort(addr)
if err != nil {
return "", fmt.Errorf("Error parsing address: %v", err)
}
return port, nil
}

// Start starts a Node instance and its network services
func (s *Server) Start() {
s.log.Info("Trying to start an Algorand node")
Expand Down Expand Up @@ -359,6 +373,20 @@ func (s *Server) Start() {
fmt.Printf("netlistenfile error: %v\n", err)
os.Exit(1)
}

addrPort, err := getPortFromAddress(addr)
if err != nil {
s.log.Errorf("Error getting port from EndpointAddress: %v", err)
}

listenAddrPort, err := getPortFromAddress(listenAddr)
if err != nil {
s.log.Errorf("Error getting port from NetAddress: %v", err)
}

if addrPort == listenAddrPort {
s.log.Warnf("EndpointAddress port %v matches NetAddress port %v. This may lead to unexpected results when accessing endpoints.", addrPort, listenAddrPort)
}
}

errChan := make(chan error, 1)
Expand Down
Loading