From 7ff8aa3a9eac746fd42c8f8974c670a7915006f6 Mon Sep 17 00:00:00 2001 From: Shivaji Kharse Date: Tue, 28 Apr 2026 01:46:10 +0530 Subject: [PATCH 1/2] fix tests --- conn/node.go | 11 ++++++++--- dgraphtest/local_cluster.go | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/conn/node.go b/conn/node.go index 16014832d6c..644756161b4 100644 --- a/conn/node.go +++ b/conn/node.go @@ -23,6 +23,8 @@ import ( "go.etcd.io/etcd/raft/v3/raftpb" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" + + "google.golang.org/grpc/connectivity" "google.golang.org/protobuf/proto" "github.com/dgraph-io/badger/v4/y" @@ -760,10 +762,13 @@ func (n *Node) joinCluster(ctx context.Context, rc *pb.RaftContext) (*api.Payloa return nil, errors.Errorf("REUSE_RAFTID: Raft ID duplicates mine: %+v", rc) } - // Check that the new node is not already part of the group. + // Reject if a peer with the same Raft ID is already registered at a + // different address AND that peer is still genuinely connected. Using the + // gRPC connection state is more accurate than IsHealthy(), which relies on + // a heartbeat timestamp and stays "healthy" for ~2s after the peer drops. if addr, ok := n.Peer(rc.Id); ok && rc.Addr != addr { - // There exists a healthy connection to server with same id. - if _, err := GetPools().Get(addr); err == nil { + if pool, err := GetPools().Get(addr); err == nil && + pool.Get().GetState() == connectivity.Ready { return &api.Payload{}, errors.Errorf( "REUSE_ADDR: IP Address same as existing peer: %s", addr) } diff --git a/dgraphtest/local_cluster.go b/dgraphtest/local_cluster.go index 5e102acdf84..85300402d0b 100644 --- a/dgraphtest/local_cluster.go +++ b/dgraphtest/local_cluster.go @@ -335,7 +335,7 @@ func (c *LocalCluster) destroyContainers() error { wg.Add(1) go func(z *zero) { defer wg.Done() - if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil { + if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !docker.IsErrNotFound(err) { errChan <- errors.Wrapf(err, "error removing zero [%v]", z.cname()) } }(zo) @@ -345,7 +345,7 @@ func (c *LocalCluster) destroyContainers() error { wg.Add(1) go func(a *alpha) { defer wg.Done() - if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil { + if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil && !docker.IsErrNotFound(err) { errChan <- errors.Wrapf(err, "error removing alpha [%v]", a.cname()) } }(aa) @@ -645,7 +645,7 @@ func (c *LocalCluster) RecreateZero(id int) error { } ro := container.RemoveOptions{RemoveVolumes: true, Force: true} - if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil { + if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !docker.IsErrNotFound(err) { return errors.Wrapf(err, "error removing zero container [%v]", z.cname()) } From 6c049f59bd687de1d2f4c8d3a2c73752156aca9f Mon Sep 17 00:00:00 2001 From: Shivaji Kharse Date: Tue, 28 Apr 2026 19:01:28 +0530 Subject: [PATCH 2/2] fix trunk check --- dgraphtest/local_cluster.go | 7 ++++--- go.mod | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dgraphtest/local_cluster.go b/dgraphtest/local_cluster.go index 85300402d0b..7423d442632 100644 --- a/dgraphtest/local_cluster.go +++ b/dgraphtest/local_cluster.go @@ -25,6 +25,7 @@ import ( "sync" "time" + cerrdefs "github.com/containerd/errdefs" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" @@ -335,7 +336,7 @@ func (c *LocalCluster) destroyContainers() error { wg.Add(1) go func(z *zero) { defer wg.Done() - if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !docker.IsErrNotFound(err) { + if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !cerrdefs.IsNotFound(err) { errChan <- errors.Wrapf(err, "error removing zero [%v]", z.cname()) } }(zo) @@ -345,7 +346,7 @@ func (c *LocalCluster) destroyContainers() error { wg.Add(1) go func(a *alpha) { defer wg.Done() - if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil && !docker.IsErrNotFound(err) { + if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil && !cerrdefs.IsNotFound(err) { errChan <- errors.Wrapf(err, "error removing alpha [%v]", a.cname()) } }(aa) @@ -645,7 +646,7 @@ func (c *LocalCluster) RecreateZero(id int) error { } ro := container.RemoveOptions{RemoveVolumes: true, Force: true} - if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !docker.IsErrNotFound(err) { + if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !cerrdefs.IsNotFound(err) { return errors.Wrapf(err, "error removing zero container [%v]", z.cname()) } diff --git a/go.mod b/go.mod index d8bb57b1c08..549a8bd65d7 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/IBM/sarama v1.47.0 github.com/Masterminds/semver/v3 v3.4.0 github.com/blevesearch/bleve/v2 v2.5.7 + github.com/containerd/errdefs v1.0.0 github.com/dgraph-io/badger/v4 v4.9.1 github.com/dgraph-io/dgo/v250 v250.0.0 github.com/dgraph-io/gqlgen v0.13.2 @@ -88,7 +89,6 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chewxy/math32 v1.11.1 // indirect - github.com/containerd/errdefs v1.0.0 // indirect github.com/containerd/errdefs/pkg v0.3.0 // indirect github.com/containerd/log v0.1.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect