From 21081f1b62d12419a1c53ced129b734f63325641 Mon Sep 17 00:00:00 2001 From: derrandz Date: Tue, 29 Jul 2025 22:45:43 +0100 Subject: [PATCH] fix: remove duplicate listen addresses when supplied to avoid muxer panic --- config/config.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 28d9c63450..dfb85552f7 100644 --- a/config/config.go +++ b/config/config.go @@ -475,6 +475,19 @@ func (cfg *Config) validate() error { return errors.New("cannot use shared TCP listener with PSK") } + // check for duplicate listen addresses and remove them + listenAddresses := cfg.ListenAddrs + // Remove duplicates while keeping the first occurrence of each address + seen := make(map[string]bool) + listenAddresses = slices.DeleteFunc(listenAddresses, func(addr ma.Multiaddr) bool { + addrStr := addr.String() + if seen[addrStr] { + return true // Remove this duplicate + } + seen[addrStr] = true + return false // Keep this first occurrence + }) + cfg.ListenAddrs = listenAddresses return nil } @@ -482,7 +495,6 @@ func (cfg *Config) validate() error { // // This function consumes the config. Do not reuse it (really!). func (cfg *Config) NewNode() (host.Host, error) { - validateErr := cfg.validate() if validateErr != nil { if cfg.ResourceManager != nil {