diff --git a/discovery/rendezvous.go b/discovery/rendezvous.go index 3e4f74ea6..3868ce7ce 100644 --- a/discovery/rendezvous.go +++ b/discovery/rendezvous.go @@ -92,6 +92,9 @@ func (r *Rendezvous) Start() error { func (r *Rendezvous) Stop() error { r.mu.Lock() defer r.mu.Unlock() + if r.client == nil { + return nil + } r.cancelRootCtx() if err := r.client.Close(); err != nil { return err diff --git a/discovery/rendezvous_test.go b/discovery/rendezvous_test.go index 922c524d1..a3522c155 100644 --- a/discovery/rendezvous_test.go +++ b/discovery/rendezvous_test.go @@ -83,6 +83,12 @@ func TestRendezvousRegisterAndDiscoverExitGracefully(t *testing.T) { require.EqualError(t, errDiscoveryIsStopped, err.Error()) } +func TestStopStoppedNode(t *testing.T) { + r, err := NewRendezvous(make([]ma.Multiaddr, 1), nil, nil) + require.NoError(t, err) + require.NoError(t, r.Stop()) +} + func BenchmarkRendezvousStart(b *testing.B) { identity, err := crypto.GenerateKey() require.NoError(b, err)