Skip to content

Commit

Permalink
Fix race condition between server shutdown and consumer info (#6356)
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
derekcollison authored Jan 9, 2025
2 parents 16df4bb + 7e92926 commit 733315a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions server/jetstream_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/jetstream_cluster_3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 733315a

Please sign in to comment.