From f3aedf51e53de42601bb97997c1d347e7dcc32ba Mon Sep 17 00:00:00 2001 From: Neil Twigg Date: Thu, 9 Jan 2025 16:24:36 +0000 Subject: [PATCH 1/2] Fix race condition between server shutdown and consumer info Signed-off-by: Neil Twigg --- server/jetstream_api.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/jetstream_api.go b/server/jetstream_api.go index 072e3e21b0..26460bd2a9 100644 --- a/server/jetstream_api.go +++ b/server/jetstream_api.go @@ -4701,10 +4701,14 @@ func (s *Server) jsConsumerInfoRequest(sub *subscription, c *client, _ *Account, return } + js.mu.RLock() + meta := cc.meta + js.mu.RUnlock() + // Since these could wait on the Raft group lock, don't do so under the JS lock. - ourID := cc.meta.ID() - groupLeader := cc.meta.GroupLeader() - groupCreated := cc.meta.Created() + ourID := meta.ID() + groupLeader := meta.GroupLeader() + groupCreated := meta.Created() js.mu.RLock() isLeader, sa, ca := cc.isLeader(), js.streamAssignment(acc.Name, streamName), js.consumerAssignment(acc.Name, streamName, consumerName) From 7e9292673075c7d5f4a37c50a71a4d08bc49a281 Mon Sep 17 00:00:00 2001 From: Neil Twigg Date: Thu, 9 Jan 2025 16:38:05 +0000 Subject: [PATCH 2/2] Fix race in `TestJetStreamClusterGhostEphemeralsAfterRestart` Signed-off-by: Neil Twigg --- server/jetstream_cluster_3_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/jetstream_cluster_3_test.go b/server/jetstream_cluster_3_test.go index e027c4ea7e..6ec202d168 100644 --- a/server/jetstream_cluster_3_test.go +++ b/server/jetstream_cluster_3_test.go @@ -1602,10 +1602,10 @@ func TestJetStreamClusterParallelConsumerCreation(t *testing.T) { func TestJetStreamClusterGhostEphemeralsAfterRestart(t *testing.T) { consumerNotActiveStartInterval = time.Second consumerNotActiveMaxInterval = time.Second - defer func() { + t.Cleanup(func() { consumerNotActiveStartInterval = defaultConsumerNotActiveStartInterval consumerNotActiveMaxInterval = defaultConsumerNotActiveMaxInterval - }() + }) c := createJetStreamClusterExplicit(t, "R3S", 3) defer c.shutdown()