{"record":{"id":"3228dbde5c3bdb6b","repo":"cilium/cilium","slug":"failed-while-adding-peer-s-with-asn-d-w","errorCode":null,"errorMessage":"failed while adding peer %s with ASN %d: %w","messagePattern":"failed while adding peer (.+?) with ASN (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/bgp/gobgp/peer.go","lineNumber":23,"sourceCode":"\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"net/netip\"\n\n\tgobgp \"github.com/osrg/gobgp/v4/api\"\n\n\t\"github.com/cilium/cilium/pkg/bgp/types\"\n)\n\n// AddNeighbor will add the CiliumBGPNeighbor to the gobgp.BgpServer, creating\n// a BGP peering connection.\nfunc (g *GoBGPServer) AddNeighbor(ctx context.Context, n *types.Neighbor) error {\n\tpeerReq := &gobgp.AddPeerRequest{\n\t\tPeer: ToGoBGPPeer(n, nil, n.Address.Is4()),\n\t}\n\tif err := g.server.AddPeer(ctx, peerReq); err != nil {\n\t\treturn fmt.Errorf(\"failed while adding peer %s with ASN %d: %w\", n.Address, n.ASN, err)\n\t}\n\treturn nil\n}\n\n// UpdateNeighbor will update the existing CiliumBGPNeighbor in the gobgp.BgpServer.\nfunc (g *GoBGPServer) UpdateNeighbor(ctx context.Context, n *types.Neighbor) error {\n\toldPeer, err := g.getExistingPeer(ctx, n.Address, n.ASN)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get existing peer: %w\", err)\n\t}\n\n\tnewPeer := ToGoBGPPeer(n, oldPeer, n.Address.Is4())\n\n\tneedsHardReset := g.needsHardReset(oldPeer, newPeer)\n\n\t// update peer config\n\tpeerReq := &gobgp.UpdatePeerRequest{\n\t\tPeer: ToGoBGPPeer(n, oldPeer, n.Address.Is4()),","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/bgp/gobgp/peer.go#L5-L41","documentation":"AddNeighbor wraps errors from the gobgp server's AddPeer gRPC call when installing a new BGP peering in the GoBGP control plane. It preserves the peer address and ASN in the message for debugging.","triggerScenarios":"Calling GoBGPServer.AddNeighbor when the underlying g.server.AddPeer rejects the peer — invalid peer address/ASN combination, duplicate/conflicting peering already configured, gobgp not yet started, or gRPC transport errors to the embedded server.","commonSituations":"Applying a CiliumBGPNeighbor whose peer already exists with a different ASN; malformed neighbor address in the CiliumBGPNodeConfig; BGP control-plane not fully initialized at reconcile time; transient gRPC unavailability.","solutions":["Read the wrapped %w error for the root gobgp failure and fix the neighbor config accordingly","Check for an existing peer with the same address but different ASN; remove or update it instead of adding","Verify the neighbor's Address parses to a valid IP and ASN is the intended value","Use UpdateNeighbor (reconcile) rather than AddNeighbor when the peer may already exist","If it's a transient gRPC/startup race, retry after the server is ready"],"exampleFix":"// before\nerr := server.AddNeighbor(ctx, n) // fails if peer exists\n// after\nif _, getErr := server.getExistingPeer(ctx, n.Address, n.ASN); getErr == nil {\n    err = server.UpdateNeighbor(ctx, n)\n} else {\n    err = server.AddNeighbor(ctx, n)\n}","handlingStrategy":"try-catch","validationCode":"if n.Address == nil || n.ASN == 0 {\n    return errors.New(\"neighbor needs a valid Address and non-zero ASN\")\n}\nif _, err := server.GetNeighbor(ctx, n.Address, n.ASN); err == nil {\n    return errors.New(\"peer already exists; use UpdateNeighbor\")\n}","typeGuard":null,"tryCatchPattern":"err := server.AddNeighbor(ctx, n)\nvar existing *types.ExistingNeighborRelationError\nif err != nil && strings.Contains(err.Error(), \"exceeds max limit\") {\n    err = server.UpdateNeighbor(ctx, n)\n}","preventionTips":["Make reconciliation idempotent: check-then-add or upsert semantics","Validate IP address and ASN before calling AddNeighbor","Retry transient gRPC errors with backoff","Log the wrapped gobgp error for root cause"],"tags":["bgp","grpc","peer-config","routing"],"backgroundTag":"bgp-peer-add-failed","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}