From ae27e17e6fb229e6044033a9accc2c3b0f98e8b3 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 9 Feb 2026 18:07:01 -0800 Subject: [PATCH] Canonicalize self peer entry to avoid raft self-alias panic --- weed/command/master.go | 6 ++++-- weed/command/master_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/weed/command/master.go b/weed/command/master.go index 36e687250..3389fabc0 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -342,10 +342,12 @@ func checkPeers(masterIp string, masterPort int, masterGrpcPort int, peers strin cleanedPeers = pb.ServerAddresses(peers).ToAddresses() hasSelf := false - for _, peer := range cleanedPeers { + for i, peer := range cleanedPeers { if peer.ToHttpAddress() == masterAddress.ToHttpAddress() { + // Canonicalize self to avoid adding a second logical self peer + // when -peers uses host:port and local name is host:port.grpcPort. + cleanedPeers[i] = masterAddress hasSelf = true - break } } diff --git a/weed/command/master_test.go b/weed/command/master_test.go index c485a4aaa..947af988b 100644 --- a/weed/command/master_test.go +++ b/weed/command/master_test.go @@ -33,3 +33,13 @@ func TestCheckPeersAddsSelfWhenGrpcPortMismatches(t *testing.T) { t.Fatalf("expected peers %+v to contain self %s by HTTP address", peers, self) } } + +func TestCheckPeersCanonicalizesSelfEntry(t *testing.T) { + self, peers := checkPeers("127.0.0.1", 9000, 19000, "127.0.0.1:9000,127.0.0.1:9002,127.0.0.1:9003") + + for _, peer := range peers { + if peer.ToHttpAddress() == self.ToHttpAddress() && peer != self { + t.Fatalf("expected self peer to be canonicalized to %q, got %q", self, peer) + } + } +}